home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / ncsat.cpt / Telnet2.5 final / main / maclook.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-14  |  75.8 KB  |  3,104 lines

  1. #ifndef lint
  2. static char *SCCSid = "%W%    (NCSA)    %G%";
  3. #endif
  4. /*#define NEW_STUFF     /* BYU - changed to "MacTCPdriver" for use in Make file. */
  5. #define NEWSLC 
  6. /*
  7. *    maclook.c
  8. *    User interface code for NCSA Telnet for the Macintosh
  9. *     by Gaige B. Paulsen
  10. ****************************************************************************
  11. *                                                                          *
  12. *      Uses    :                                                               *
  13. *      TCP/IP kernel for NCSA Telnet                                       *
  14. *      by Tim Krauskopf                                                    *
  15. *       with Macintosh code by Gaige B. Paulsen                                *
  16. *                                                                          *
  17. *      National Center for Supercomputing Applications                     *
  18. *      152 Computing Applications Building                                 *
  19. *      605 E. Springfield Ave.                                             *
  20. *      Champaign, IL  61820                                                *
  21. *                                                                          *
  22. *                                                                          *
  23. ****************************************************************************
  24. *
  25. *   User interface for basic telnet with background file transfer
  26. *   capabilities via FTP calls from host.
  27. *
  28. *    This, the Macintosh version also gives each session its own window,
  29. *    provides advanced keyboard translation, Tek emulation, printing/copying
  30. *    of text and graphics and the pasting of text into the active session.
  31. *
  32. *        Requires:
  33. *    config.c- Aux. file for handling telnet documents
  34. *    menu.c    - Aux. file for handling menu calls
  35. *    event.c    - Aux. file for handling events
  36. *    switch.c- Aux. file for handling swithcher  (the J word is in Event and here )
  37. */
  38.  
  39. /*
  40.  *    Files for inclusion.
  41.  */
  42. #include    <stdio.h>
  43. #include <string.h>
  44. #include <stdlib.h>
  45.  
  46. #include    <Appletalk.h>
  47. #include    <Controls.h>
  48. #include    <CType.h>
  49. #include    <Desk.h>
  50. #include     <Devices.h>
  51. #include    <Dialogs.h>
  52. #include    <Events.h>
  53. #include    <Fonts.h>
  54. #include    <FCntl.h>
  55. #include    <Memory.h>
  56. #include    <Menus.h>
  57. #include    <Packages.h>
  58. #include    <Files.h>
  59. #include    <OSUtils.h>
  60. #include    <Quickdraw.h>
  61. #include    <Resources.h>
  62. #include    <SegLoad.h>
  63. #include     <Strings.h>
  64. #include    <TextEdit.h>
  65. #include    <ToolUtils.h>
  66. #include    <Types.h>
  67. #include    <Windows.h>
  68. #include    <OSEvents.h>
  69. #include     <Strings.h>
  70.  
  71. #include    "wind.h"
  72. #include    "configrec.h"
  73. #include    "hostform.h"
  74. #include "event.h"
  75. #include "croft.h"
  76. #include "macutil.h"
  77. #include "atalk.h"
  78. #include "maclook.h"
  79. #define PREFMASTER
  80. #include    "prefs.h"
  81.  
  82. #include "whatami.h"
  83. #include "rsmac.h"
  84. #include "confile.h"
  85. #include    "vsdata.h"
  86. #include    "vskeys.h"
  87. #include "vsinterf.h"
  88. #include "vgtek.h"
  89. #include "tekrgmac.h"
  90. #include "rr.h"
  91. #include "vr.h"
  92. #include "vrrgmac.h" 
  93. #include "user.h"
  94. #include "util.h"
  95. #include "netevent.h"
  96. #include "config.h"
  97. #include "environ.h"
  98. #include "switch.h"
  99. #include "menu.h"
  100. #include "ser.h"                /* BYU 2.4.15 MPW */
  101. #include "slip.h"                /* BYU 2.4.15 MPW */
  102. #if 0                            /* BYU 2.4.7 */
  103. #include <MacTCPCommonTypes.h>
  104. #include <AddressXlation.h>
  105. #endif                            /* BYU 2.4.7 */
  106. #include "dnr.c"
  107.  
  108. #ifdef MPW
  109. #include "mpw.h"
  110. #endif MPW
  111.  
  112. /*
  113.  *    Operation Governing Defines:
  114.  */
  115.  
  116. #define    MaxSess        20        /* The maximum number of sessions */
  117. #define    MaxGraph    30        /* Maximum number of graphics */
  118.  
  119.  
  120. /*
  121.  *    Emulation type defines
  122.  */
  123.  
  124. #define VTEKTYPE 1
  125. #define TEKTYPE 2
  126. #define DUMBTYPE 3
  127. #define RASTYPE 4
  128.  
  129.  
  130.     #define SLC 3 
  131.         #define SLC_NOSUPPORT    0
  132.         #define SLC_CANTCHANGE    1
  133.         #define SLC_VALUE        2
  134.         #define SLC_DEFAULT        3
  135.         #define SLC_LEVELBITS    3
  136.         #define SLC_AWK            128
  137.         #define SLC_SYNCH        1
  138.         #define SLC_BRK            2
  139.         #define SLC_IP            3
  140.         #define SLC_AO            4
  141.         #define SLC_AYT            5
  142.         #define SLC_EOR            6
  143.         #define SLC_ABORT        7
  144.         #define SLC_EOF            8
  145.         #define SLC_SUSP        9
  146.         #define SLC_EC            10
  147.         #define SLC_EL           11
  148.         #define SLC_EW           12
  149.         #define SLC_RP            13
  150.         #define SLC_LNEXT        14
  151.         #define SLC_XON            15
  152.         #define SLC_XOFF        16
  153.         #define SLC_FORW1        17
  154.         #define SLC_FORW2        18
  155.  
  156. /*
  157.  *    Service type defines
  158.  */
  159.  
  160. /*
  161.  *    Font Height and width constants
  162.  */
  163. #define Fheight 11
  164. #define Fwidth 6
  165. #define Fright 480
  166.  
  167. #define DefFONT 4
  168. #define DefSIZE 9
  169. /*
  170.  *    Window constraints
  171.  */
  172.  
  173. #define MAXWINDOWHEIGHT 18+Fheight*24
  174. #define MAXWINDOWWIDTH  17+Fwidth*80+3
  175.  
  176. /*
  177.  *    Resource Defines
  178.  */
  179.  
  180.  
  181. #define    FirstDLOG    1023
  182. #define    AboutDLOG    256
  183. #define    ConnAttDLOG    258
  184. #define    ConnFalDLOG    303
  185. #define BadMaskDLOG    330
  186. #define BadIPDLOG    331
  187.  
  188. #define    GetParmDLOG    300
  189. #define GetDefDLOG 1300     /* Config net for MacTCP version */
  190. #define    GetParmIP    5        /* The IP number TE */
  191. #define GetParmHOST    10        /* The Default Host TE */
  192. #define    GetParmMASK    7        /* The Subnet Mask TE */
  193. #define    GetParmStat    3        /* The Static IP RB */
  194. #define    GetParmKDyn    4        /* The Dynamic IP RB */
  195. #define    GetParmUseM    6        /* The Use Mask CB */
  196. #define GetCaptureName 12    /* NCSA 2.5: Name of capture file */
  197.  
  198. #define    BadHostDLOG    301
  199. #define    BadHostQuit    3        /* The Quit Button */
  200. #define    BadHostCont    2        /* The Continue Button */
  201.  
  202.  
  203. #define RESOLVERERROR 128
  204. #define    GetDestDLOG    257
  205. #define    GDdest        3        /* The Destination filed in GetDest dialog */
  206.  
  207. #define    XferCURS    290
  208. #define    GINCURS        257
  209. #define    DbugCURS    268
  210. #define    POSCURS        256
  211.  
  212. #define    IPnumSTR    256
  213. #define    HostSTR        257
  214. #define    MaskSTR        258
  215. #define FileSTR        1024        /* NCSA 2.5: name of capture file */
  216. #define    FTPlogWIND    257
  217.  
  218. /*
  219.  * Event Auxilliary Defines
  220.  */
  221.  
  222.  
  223.  
  224. /*
  225.  * ASCII character set defines
  226.  */
  227.  
  228. #define ESC            0x1b    /* the escape character */
  229. #define    BS            0x08    /* the backspace character */
  230. #define DEL            0x7f    /* the delete character */
  231. #define CR            0x0d    /* the carriage return character */
  232. #define LF            0x0a    /* the line feed character */
  233.  
  234.  
  235.  
  236. #define EDcopy        4        /* Edit Menu: Copy */
  237. #define EDpaste        5        /* Edit Menu: Paste */
  238. #define EDcopyt        7        /* Edit Menu: Copy Table */
  239. #define Edit    2
  240. #define    Emul        3        /*    Emulation Menu's position */
  241.  
  242. #define GetStrRes(x)    (Str255 **)GetResource('STR ',(x));    /* NCSA 2.5 */
  243.  
  244.  
  245. #ifdef OPTSDEBUG
  246. char *telstates[]={
  247.     "SE",
  248.     "NOP",
  249.     "DM",
  250.     "BREAK",
  251.     "IP",
  252.     "ABORT",
  253.     "AYT",
  254.     "ERASE CHAR",
  255.     "ERASE LINE",
  256.     "GO AHEAD",
  257.     "SB",
  258.     "WILL",
  259.     "WONT",
  260.     "DO",
  261.     "DONT"
  262. };
  263.  
  264. char *teloptions[256]={
  265.     "Binary",                /* 0 */
  266.     "Echo",
  267.     "Reconnection",
  268.     "Supress Go Ahead",
  269.     "Message Size Negotiation",
  270.     "Status",                /* 5 */
  271.     "Timing Mark",
  272.     "Remote Controlled Trans and Echo",
  273.     "Output Line Width",
  274.     "Output Page Size",
  275.     "Output Carriage-Return Disposition",    /* 10 */
  276.     "Output Horizontal Tab Stops",
  277.     "Output Horizontal Tab Disposition",
  278.     "Output Formfeed Disposition",
  279.     "Output Vertical Tabstops",
  280.     "Output Vertical Tab Disposition",        /* 15 */
  281.     "Output Linefeed Disposition",
  282.     "Extended ASCII",
  283.     "Logout",
  284.     "Byte Macro",
  285.     "Data Entry Terminal",                    /* 20 */
  286.     "SUPDUP",
  287.     "SUPDUP Output",
  288.     "Send Location",
  289.     "Terminal Type",
  290.     "End of Record",                        /* 25 */
  291.     "TACACS User Identification",
  292.     "Output Marking",
  293.     "Terminal Location Number",
  294.     "3270 Regime",
  295.     "X.3 PAD",                                /* 30 */
  296.     "Negotiate About Window Size",
  297.     "Terminal Speed",
  298.     "Toggle Flow Control",
  299.     "Linemode",
  300.     "X Display Location",                    /* 35 */
  301.     "36","37","38","39",
  302.     "40","41","42","43","44","45","46","47","48","49",
  303.     "50","51","52","53","54","55","56","57","58","59",
  304.     "60","61","62","63","64","65","66","67","68","69",
  305.     "70","71","72","73","74","75","76","77","78","79",
  306.     "80","81","82","83","84","85","86","87","88","89",
  307.     "90","91","92","93","94","95","96","97","98","99",
  308.     "100","101","102","103","104","105","106","107","108","109",
  309.     "110","111","112","113","114","115","116","117","118","119",
  310.     "120","121","122","123","124","125","126","127","128","129",
  311.     "130","131","132","133","134","135","136","137","138","139",
  312.     "140","141","142","143","144","145","146","147","148","149",
  313.     "150","151","152","153","154","155","156","157","158","159",
  314.     "160","161","162","163","164","165","166","167","168","169",
  315.     "170","171","172","173","174","175","176","177","178","179",
  316.     "180","181","182","183","184","185","186","187","188","189",
  317.     "190","191","192","193","194","195","196","197","198","199",
  318.     "200","201","202","203","204","205","206","207","208","209",
  319.     "210","211","212","213","214","215","216","217","218","219",
  320.     "220","221","222","223","224","225","226","227","228","229",
  321.     "230","231","232","233","234","235","236","237","238","239",
  322.     "240","241","242","243","244","245","246","247","248","249",
  323.     "250","251","252","253","254",
  324.     "Extended Options List"        /* 255 */
  325. };
  326.  
  327. char *LMoptions[]={
  328.     "None",
  329.     "SYNCH",
  330.     "BREAK",
  331.     "IP",
  332.     "ABORT OUTPUT",
  333.     "AYT",
  334.     "EOR",
  335.     "ABORT",
  336.     "EOF",
  337.     "SUSP",
  338.     "EC",
  339.     "EL",
  340.     "EW",
  341.     "RP",
  342.     "LNEXT",
  343.     "XON",
  344.     "XOFF",
  345.     "FORW1",
  346.     "FORW2",
  347.     "MCL",
  348.     "MCR",
  349.     "MCWL",
  350.     "MCWR",
  351.     "MCBOL",
  352.     "MCEOL",
  353.     "INSRT",
  354.     "OVER",
  355.     "ECR",
  356.     "EWR",
  357.     "EBOL",
  358.     "EEOL"
  359. };
  360.  
  361. char *LMflags[]={
  362.     "NOSUPPORT",
  363.     "CANTCHANGE",
  364.     "VALUE",
  365.     "DEFAULT"
  366. };
  367. #endif
  368.  
  369.  
  370.  
  371. #define MAXVG 20 /* maximum number of VG windows */
  372.  
  373. #ifdef SMTP            /* External Var for SMTP */
  374. extern int smnum;
  375. #endif
  376.  
  377. /*
  378.  *    Type declarations for Globals
  379.  */
  380. Cursor
  381.     *gincurs,        /* Cursor when in graphics input mode */
  382.     *xfercurs,        /* Cursor when in transfer mode */
  383.     *normcurs,        /* Cursor for non-transfer normal mode */
  384.     *textcurs,        /* Cursor for text mode */
  385.     *poscurs,        /* Cursor for positioning mode */
  386.     *watchcurs,        /* Cursor for time-taking operations */
  387.     *graphcurs;        /* Cursor for graphics windows */
  388. Rect
  389.     screenRect,        /* The whole screen */
  390.     dragRect,        /* Where it is legal to drag ourselves */
  391.     SizRect;        /* How big/small our windows can be */
  392. Str255
  393.     *defaultd,        /* Default host name */
  394.     *dvs;            /* Default Volume/directory specification */
  395.  
  396. WindRec
  397.     *screens,        /* Window Records (VS) for :    Current Sessions */
  398.     ftplog,            /*                                FTP Log             */
  399.     console;        /*                                console Window   */
  400.  
  401. int
  402.     SettingsFile=-1,/* The Resource Reference Number of the Settings file */
  403.     neton    = 0,    /* Has the network been set up right? */
  404.     ginon   = 0,    /* True if we are in GIN mode */
  405.     xferon  = 0,    /* Is a transfer in progress */
  406.     dynamic = 0,    /* not dynamic by default.... */
  407.     userlevel=0,    /* The user privelege level... 0 allows reconfig on fly */
  408.     numwindows=0,    /* Number of active window structures (note: not windows ) */
  409.     scrn=0,            /* Currently active screen */
  410.     graphs=0,        /* How many detached graphs do we have */
  411.     oldgraph[MaxGraph],    /* Storage for old Graph numbers */
  412.     debug=1,            /* Flag for debugging 1=active */
  413.     done=0,            /* Are we done yet 0=not */
  414.     net_okay,        /* BYU serial */
  415.     KIP=0,            /* is KIP gateway present */
  416.     ipn[4];            /* The real IP number */
  417.  
  418. long
  419.     defmask,        /* The network mask as per defaults contingent on the IP */
  420.     mynetmask;        /* The network mask as per user config */
  421.  
  422. unsigned char
  423.     TermType[32],    /* Termtype to send */
  424.     myipnum[4];        /* My IP number (internal) */
  425. AddrBlock
  426.     KIPserver;        /* KIP gateway address */
  427.  
  428. int *DirTree;
  429. char *mungbuf;
  430. short                /* BYU 2.4.7 - must match "extern" declaration in "menu.c". */
  431.     cmask,            /* Are we using a custom mask */
  432.     err;            /* Error variable */
  433.  
  434. OSErr io;
  435.  
  436. extern OSErr                     /* BYU 2.4.7 */
  437.     OpenResolver(fileName);        /* BYU 2.4.7 */
  438.  
  439. extern int            /* BYU */
  440.     RGMalloc();        /* BYU */
  441.  
  442. extern void         /* BYU */
  443.     init_mb_files(),/* BYU */
  444.     AdjustMenus(),    /* BYU */
  445.     VGalloc();        /* BYU */
  446.  
  447. extern MenuHandle    myMenus[];
  448. #define COnext        1        /* Connection Menu: Next Session... */
  449. #define Conn        5        /*    Connection Menu's position */
  450.  
  451. extern VSscrn *VSIw;
  452.  
  453. void DoTheMenuChecks();
  454. /*
  455.  *    Type declarations for functions
  456.  */
  457.  
  458. int
  459.     getWDnum();
  460. char
  461.     *strncpy(),
  462.     *neterrstring();
  463. Str255
  464.     *getWDname();
  465. pascal void
  466.     VersionNumber(),
  467.     OutlineItem(),
  468.     ScrollProc();
  469. pascal int
  470.     modalProc();
  471.  
  472. GrafPtr
  473.     RSgetwindow();
  474.  
  475. extern short             /* BYU 2.4.15 */
  476.     slip_connection;    /* BYU 2.4.15 */
  477.  
  478. extern int
  479.     whichMenus,        /* Are we commanded or not ?*/
  480.     HFS,            /* True if HFS is active/ false if not */
  481.     EtherNet;        /* The all-powerful! */
  482. extern
  483. SysEnvRec
  484.     theWorld;        /* The state of the machine address */
  485. extern
  486. char
  487.     *VERSION;        /* Version Information */
  488.  
  489. #ifdef JOHN_DEERE
  490.     int jdp;
  491. #endif
  492.  
  493. void UItemAssign
  494.   (
  495.     DialogPtr dlog,
  496.     int item,
  497.     int (*proc)()
  498.   ) /* sets the handler for a user item to the specified procedure. */
  499. {
  500.     Rect ibox;
  501.     char **ihndl;
  502.     short typ;
  503.  
  504.     GetDItem( dlog, item, &typ, &ihndl, &ibox);
  505.     SetDItem( dlog, item,  typ, (Handle) proc, &ibox);
  506. }
  507.  
  508. void HostIsAppl
  509.   (
  510.     void
  511.   )
  512. {
  513.     Str255 fileName;
  514.     short dumint;
  515.     Handle dumlong;
  516.     char *nnmm, *from;
  517.     
  518.     getappparms( &fileName, &dumint, &dumlong);
  519.     nnmm = (char *) NewPtr( 64);
  520.     if (nnmm ==NULL) {
  521.         OtherError("Can't allocate space for","default config.tel name");
  522.         quit();
  523.         }
  524.     from = &fileName;            /* Convert to a real format... */
  525.  
  526.     from = strncpy( nnmm,from, 63);            /* Strcpy sort of ... */
  527.     nnmm[63]=0;
  528.     Shostfile(nnmm);
  529. }
  530.  
  531. /*
  532.  *            T h e        M  A  I  N            P r o g r a m
  533.  */
  534.  
  535. void initmac
  536.   (
  537.     void
  538.   )
  539. {
  540.     char **userstring;
  541.     EventRecord myEvent;
  542.     int i;
  543.  
  544.     InitGraf(&qd.thePort);
  545.     InitFonts();
  546.     InitWindows();
  547.     InitMenus();
  548.     TEInit();
  549.     InitDialogs(0L);
  550.     InitCursor();
  551.  
  552.     /* MaxApplZone(); */
  553.     MoreMasters();                    /* I want memory, */
  554.     MoreMasters();                    /* Lots of Memory, */
  555.     MoreMasters();                    /* I want ApplHeap, and SysHeap, and more */
  556.     MoreMasters();                    /* Give me handles, and pointers...... */
  557.     MoreMasters();
  558.     MoreMasters();
  559.     MoreMasters();
  560.  
  561. #ifndef REAL
  562.     err=openresfile("ncsa.rsrc");    /* We don't want to RESedit too much */
  563. #endif
  564.  
  565.     InquireEnvironment();
  566.  
  567.     for (i=1;i<12;i++)
  568.         EventAvail( 0xffff, &myEvent);
  569.     setupmenu( 0);                /* Temporarily default to old menus.... */
  570.  
  571.     screenRect = qd.screenBits.bounds;            /* well, they have to be set */
  572.                                                 /* somewhere, where else ? */
  573.     SetRect(&dragRect, 4, 24, screenRect.right-4, screenRect.bottom-4);
  574.     SetRect(&SizRect,    10*Fwidth+18,  3 *Fheight+18,
  575.                         80*Fwidth+18, 24 *Fheight+18);
  576.  
  577.     userstring =GetResource('NCSA',1);
  578.  
  579.     if (userstring !=0L) {
  580.         userlevel= **userstring -'0';
  581.         if (userlevel<0) userlevel=32767;
  582.         if (userlevel>3) HostIsAppl();        /* Don't use config.tel <UAS> */
  583.         }
  584. }
  585.  
  586. /*
  587.  * checkdebug - check to see if they clicked on a debug file
  588.  */
  589.  
  590. int checkdebug
  591.   (
  592.     void
  593.   )
  594. {
  595.     short i,mess,count;
  596.     AppFile theFile;
  597.  
  598.     CountAppFiles(&mess,&count);
  599.     if (mess==1) return(FALSE);
  600.     if (count<1) return(FALSE);
  601.     for(i=1;i<=count;i++) {
  602.         GetAppFiles(i, &theFile);
  603.         if (theFile.fType=='DBUG') {
  604.             ClrAppFiles(i);
  605.             return(TRUE);
  606.             }
  607.         if (theFile.fType=='TEXT') {
  608.             char *nnmm, *from;
  609.             ClrAppFiles(i);
  610.             nnmm = (char *) NewPtr( 64);
  611.             if (nnmm ==NULL) {
  612.                 OtherError("Can't allocate space for","default config.tel name");
  613.                 quit();
  614.                 }
  615.             from = &theFile.fName;            /* Convert to a real format... */
  616.  
  617.             p2cstr(from);
  618.             from = strncpy( nnmm,from, 63);            /* Strcpy sort of ... */
  619.             nnmm[63]=0;
  620.             Shostfile(nnmm);
  621.             }
  622.         }
  623.     return(FALSE);
  624. }
  625.  
  626. void putln                                    /* Put a C string on the console */
  627.   (
  628.     char *cp
  629.   )
  630. {
  631.     int temp;
  632.  
  633.     if (!debug)
  634.         return;
  635.  
  636.     temp=strlen(cp);
  637.     if (temp>80) return;
  638.     VSwrite(console.vs,cp,temp);
  639.     VSwrite(console.vs,"\015\012",2);
  640. }
  641.  
  642. /*
  643.  *    initmcurs - Set up the mouse Cursors
  644.  *        NOTE: debug tells if the bug or the pointer is to be used as dflt.
  645.  */
  646.  
  647. void loadcursor
  648.   (
  649.     int CursorID,
  650.     CursPtr *result
  651.   )
  652.   /* copies a specified cursor from a resource into a nonrelocatable block
  653.     and returns a pointer to it in *result. */
  654.   {
  655.     CursHandle tempcurs;
  656.     OSErr Err;
  657.  
  658.     *result = nil;
  659.     do /* once */
  660.       {
  661.         tempcurs = GetCursor(CursorID);
  662.         Err = ResError();
  663.         if (Err != noErr)
  664.             break;
  665.         (Ptr) *result = NewPtr(sizeof(Cursor));
  666.         Err = MemError();
  667.         if (Err != noErr)
  668.             break;
  669.         LoadResource((Handle) tempcurs); /* in case it was purged */
  670.         Err = ResError();
  671.         if (Err != noErr)
  672.             break;
  673.         BlockMove((Ptr) *tempcurs, (Ptr) *result, sizeof(Cursor));
  674.       }
  675.     while (false);
  676.     if (Err != noErr)
  677.       {
  678.         if (*result != nil)
  679.             DisposPtr((Ptr) *result);
  680.         *result = &qd.arrow;
  681.       }
  682.   } /* loadcursor */
  683.  
  684. void initmcurs
  685.   (
  686.     int debug
  687.   ) /* initializes all the mouse cursors for later use */
  688.   {
  689.     loadcursor(watchCursor, &watchcurs);
  690.     loadcursor(crossCursor, &graphcurs);
  691.     loadcursor(POSCURS, &poscurs);
  692.     loadcursor(iBeamCursor, &textcurs);
  693.     loadcursor(GINCURS, &gincurs);
  694.     loadcursor(XferCURS, &xfercurs);
  695.     if (debug)
  696.         loadcursor(DbugCURS, &normcurs);
  697.     else
  698.         normcurs = &qd.arrow;
  699.     SetCursor(normcurs);
  700.   }
  701.  
  702. /*
  703.  * initconsole - initialize the  console window
  704.  */
  705.  
  706. void initconsole
  707.   (
  708.     void
  709.   )
  710. {
  711.     Rect pRect;
  712.  
  713.     SetRect(&pRect,15,287,15+MAXWINDOWWIDTH /*495,335 */, 287+MAXWINDOWHEIGHT);
  714.     console.vs=RSnewwindow( &pRect, 50, 80, 24,
  715.                             "<console>", 1, DefFONT, DefSIZE, debug,0,0); /* NCSA 2.5 */
  716.     console.wind = RSgetwindow( console.vs);
  717.  
  718.     VSwrite(ftplog.vs,"\033[24;0H",1);        /* Move to bottom of screen */
  719.  
  720.     console.active=0;console.port=0;
  721.     console.termstate=VTEKTYPE;
  722.     console.name="<console>";
  723. }
  724.  
  725. /*
  726.  * initftplog - initialize the FTP log window
  727.  */
  728.  
  729. void initftplog
  730.   (
  731.     void
  732.   )
  733. {
  734.     Rect prect;
  735.  
  736.     SetRect(&prect, 300,256,512,384);
  737.  
  738.     ftplog.vs=RSnewwindow( &prect, 50, 80, 24,
  739.                             "FTP Log", 1, DefFONT, DefSIZE,0,0,0); /* NCSA 2.5 */
  740.     ftplog.wind = RSgetwindow( ftplog.vs);
  741.  
  742.     VSwrite(ftplog.vs,"\033[24;0H",7);        /* Move to bottom of screen */
  743.     ftplog.active=0;                         /* Meaningless */
  744.     ftplog.port=0;                            /* As is this */
  745.     ftplog.termstate=VTEKTYPE;
  746.     ftplog.name="FTP Log";                    /* And most of these */
  747.  
  748. }
  749.  
  750. /*
  751.  *    initwd - Initialize the working directory pointers
  752.  */
  753.  
  754. void initwd
  755.   (
  756.     void
  757.   )
  758. {
  759.     extern int defaultv;
  760.  
  761.     defaultv=getWDnum();
  762.     dvs=getWDname();
  763.     VSwrite(console.vs,&(*dvs)[1],(int) (*dvs)[0]);
  764. }
  765.  
  766. int ckhostfile
  767.   (
  768.     void
  769.   )
  770. {
  771.     DialogPtr dtemp;
  772.     char *from,*nnmm;
  773.     Point where;
  774.     SFReply sfr;
  775.     SFTypeList    sfl;
  776.     int temp=0;
  777.     short item=0;
  778.     Str255 *dir;
  779.  
  780.  
  781.     dtemp=GetNewDialog( BadHostDLOG,(Ptr) 0L,(WindowPtr) -1L);
  782.     while( item<1 || item>2 )
  783.         ModalDialog((ModalFilterProcPtr) modalProc ,&item);
  784.     DisposDialog(dtemp);
  785.  
  786.     if ( item==BadHostQuit ) return(-1);
  787.     if ( item==BadHostCont ) return(-1);        /* changed, continue not allowed */
  788.  
  789.     where.h=100; where.v=100;
  790.     sfl[0]='TEXT';                    /* All TEXT files are Game */
  791.  
  792.     sfgetfile( pass(where), "Select Host File:", 0L,1,sfl,0L,&sfr);
  793.  
  794.     if (!sfr.good) {
  795.         putln("got bad filename");    /* Possibly/Probably Cancel */
  796.         return(-1);
  797.         }
  798.  
  799.     setvol( 0L, sfr.vRefNum);        /* I like HFS, I like HFS, except when it is a pain */
  800.  
  801.     nnmm = (char *) NewPtr( 64);
  802.     if (nnmm ==NULL) {
  803.         OtherError("Can't allocate space for","modified config.tel name");
  804.         quit();
  805.         }
  806.     from = &sfr.fName;            /* Convert to a real format... */
  807.  
  808.     p2cstr(from);
  809.     dir = getWDname();
  810.     (*dir)[++(*dir)[0]]='/';
  811.     VSwrite( console.vs, &(*dir)[1], (int) (*dir)[0]);    /* Preview pathspec... */
  812.     putln(from );                        /* preview.... */
  813.  
  814.     from = strncpy( nnmm,from, 63);            /* Strcpy sort of ... */
  815.     nnmm[63]=0;
  816.  
  817.     Shostfile(nnmm);
  818.  
  819.     return(0);
  820. }
  821.  
  822. /*
  823.  * initnet - init all of the network stuff...
  824.  */
  825.  
  826. void initnet
  827.   (
  828.     int debug
  829.   )
  830. {
  831. #pragma unused(debug)
  832.     struct config conf;
  833.     int error;
  834.  
  835.     error=Snetinit();
  836.  
  837.     if (error!=0 && error!=-2) {            /* if cant find hosts file, give em another */
  838.         ShowAllErrors();
  839.         if (ckhostfile()) {            /* BYU */
  840.             quit();                    /* BYU - shot, if that fails.... */
  841.             return;                    /* BYU */
  842.             }                        /* BYU */
  843.         if (Snetinit()!=0)     {        /* Ok, but only one more chance or we'll.... */
  844.             HostIsAppl();
  845.             ShowAllErrors();
  846.     
  847.             error=Snetinit();
  848.             if (error!=0 && error!=-2) {
  849.                 ShowAllErrors();
  850.                 quit();    /* Squash 'em like a grape! */
  851.                 return;                /* BYU */
  852.                 }
  853.             }
  854.         }
  855.     if (error == -2)
  856.         reconfigNetwork(0);
  857.  
  858.     neton=1;
  859.     TickCount();
  860.     Sgetconfig(&conf);
  861.     if (conf.comkeys)
  862.         whichMenus=1;
  863.     else
  864.         whichMenus=0;
  865.     strcpy(TermType,conf.termtype);
  866.     switchMenus(whichMenus);
  867.  
  868.     if (conf.timesl>=0) JTime(conf.timesl);
  869.     if (conf.textblock > 0)  
  870.         setblocksize(conf.textblock);        /* network read-buffer size */
  871.     else 
  872.         setblocksize(120);
  873.  
  874. #ifdef SMTP
  875.     setSMTP();                        /* anyone wanna receive mail ? */
  876. #endif
  877.  
  878. }
  879.  
  880. main()
  881. {
  882.     DialogPtr dtemp;        /* Used for storage of the copyright dlog */
  883.  
  884.  
  885.     DirTree = (int *)NewPtr(256*sizeof(int));
  886.     mungbuf = (char *)NewPtr(1024);
  887.     
  888.     FlushEvents(everyEvent,0);
  889.     initmac();                /* initialize Macintosh stuff */
  890.  
  891.     debug=checkdebug();        /* must return TRUE or FALSE */
  892.  
  893.     initmcurs(debug);        /* init the mouse cursor */
  894.     SetCursor(watchcurs);
  895.  
  896.     if (RGMalloc()) {        /* BYU - save global space */
  897.         short item;
  898.         ParamText(0L, 0L, 0L, "\pInsufficient memory for TEK graphics");
  899.         dtemp = GetNewDialog(302, (Ptr) 0L, (WindowPtr) -1L);
  900.         ModalDialog(0L, &item);
  901.         DisposDialog(dtemp);
  902.         return;
  903.     }                        /* BYU */
  904.     VGalloc();                /* BYU - save global space */
  905.     VSinit(MaxSess+2);                /* initialize the Virtual Screen */
  906.     
  907.     screens = (WindRec *)NewPtr(MaxSess*sizeof(WindRec));
  908.  
  909.     initconsole();            /* allocate/initialize console screen */
  910.  
  911. /*    initEvents();            /* BYU 2.4.18 - Do Juggler stuff if necessary */
  912.  
  913.     dtemp=GetNewDialog(FirstDLOG,(Ptr) 0L,(WindowPtr) -1L);    /* opening dialog */
  914.     UItemAssign( dtemp, 2, (int (*)()) VersionNumber);
  915.     putln("past version number");
  916.     DrawDialog(dtemp);                /* while we init everything */
  917.  
  918.     initftplog();            /* allocate/initialize ftp log screen */
  919.     putln("past initftplog");
  920.     VGinit();                /* initialize Virtual Graphics after VS so that */
  921.                             /* init messages can come on console screen */
  922.     VRinit();
  923.     MacRGinit();
  924.     initwd();                /* init working/file transfer directory */
  925.  
  926.  
  927.     net_okay = TRUE;        /* BYU serial - assume okay (necessary for initnet()). */
  928.     initnet(debug);            /* initialize TK's network stuff */
  929.     if (done || !neton)        /* BYU serial */
  930.         net_okay = FALSE;    /* BYU serial */
  931.     else                    /* BYU serial */
  932.         net_okay = TRUE;    /* BYU serial */
  933.  
  934.     done = FALSE;            /* BYU serial */
  935.  
  936.     init_serial();            /* BYU serial */
  937.     initslip();                /* BYU 2.4.15 */
  938.  
  939.     init_mb_files();        /* BYU - initialize file id's to closed state */
  940.                     /* if initipnum() then FatalError("Can't run w/o IP number"); */
  941. /*    initipnum( Button() && (userlevel==1)); */
  942.  
  943.                                             /* get the IP number (w/reconfigure) */
  944.     SetCursor(normcurs);
  945.  
  946.     GetPrefs();                /* Load user preferences  (must be after initipnum) */
  947.     initEvents();            /* BYU 2.4.18 - Must be after GetPrefs() */
  948.     netgetip( myipnum);        /* Just in case it was RARPed */
  949.     initswitch();            /* initialize switcher stuff if necessary */
  950.  
  951.  
  952.     if (EtherNet == -99) {                            /* BYU 2.4.16 */
  953.         io = OpenResolver(NULL);                    /* BYU 2.4.16 */
  954.  
  955.         if (io) {                                    /* BYU 2.4.16 */
  956.             DialogPtr theErrDialog;                    /* BYU 2.4.16 */
  957.             short itemhit=0;                        /* BYU 2.4.16 */
  958.  
  959. /* BYU serial - "Unable to open resolver" message. */
  960.             theErrDialog = GetNewDialog(RESOLVERERROR,(Ptr)0L,(WindowPtr)-1L);    /* BYU 2.4.16 */
  961.             DrawDialog(theErrDialog);                                    /* BYU 2.4.16 */
  962.             while (!itemhit)                                             /* BYU 2.4.16 */
  963.                 ModalDialog((ModalFilterProcPtr) modalProc,&itemhit);    /* BYU 2.4.16 */
  964.             EtherNet = -100;                                            /* BYU 2.4.16 */
  965. /*            quit();                                    /* BYU 2.4.16 */
  966.         }                                            /* BYU 2.4.16 */
  967.     }                                                /* BYU 2.4.16 */
  968.  
  969. /*    Ssetgates();                    /* BYU serial - finishes IP inits */
  970.  
  971.     updateMenuChecks();
  972.     DoTheMenuChecks();
  973.     
  974.     if (!checkCONF())                 /* Configuration files? */
  975.         DrawDialog(dtemp);            /* while we init everything */
  976.  
  977.     DisposDialog(dtemp);            /* Take it off.....all off......*/
  978.  
  979. #ifdef JOHN_DEERE
  980.     jdp = netlisten( 2001,0);        /* BYU 2.4.15 */
  981. #endif
  982.  
  983.     do {                        /* BYU - Do this forever */
  984.                                             /* Getting a tad bit small..... */
  985.  
  986. #ifdef SMTP
  987.         rSMTPd();
  988. #endif
  989.         DoEvents();
  990.         if (!done) DoModem();                    /* BYU serial - watch serial port */
  991.         if (!done && net_okay) DoNetEvents();    /* BYU serial - act like the postman */
  992.  
  993.     } while (!done);            /* BYU mod */
  994. /*    quit();        /* BYU - TWIMC: this statement never used to execute */
  995. }
  996.  
  997. putstr(cp)                                    /* Put an STR255 on the console */
  998. char *cp;
  999. {
  1000.     int temp;
  1001.     temp = cp[0];
  1002.     if (temp > 80)
  1003.         return;
  1004.     VSwrite(console.vs, &cp[1], temp);
  1005.     VSwrite(console.vs, "\015\012", 2);
  1006. }
  1007.  
  1008. vsput(c)                                    /* Put a single char on the console */
  1009. char c;
  1010. {
  1011.     VSwrite(console.vs,&c,1);
  1012. }
  1013.  
  1014. void ftpmess                                /* Put a C string on the console */
  1015.   (
  1016.     char *cp
  1017.   )
  1018. {
  1019.     int temp;
  1020.     temp=strlen(cp);
  1021.     if (temp>80 || temp < 1) return;
  1022.     VSwrite(ftplog.vs,cp,temp);
  1023. }
  1024.  
  1025. int detachGraphics
  1026.   (
  1027.     int dnum
  1028.   )
  1029. {
  1030.     int i=0;
  1031.  
  1032.     while((i<numwindows) && (dnum!=screens[i].curgraph)) i++;
  1033.     if (i>=numwindows) return(-1);
  1034.     oldgraph[graphs++]=dnum;
  1035.     screens[i].curgraph=-1;
  1036.     screens[i].termstate=VTEKTYPE;
  1037.     screens[i].enabled=1;
  1038.     RGdetach(dnum);
  1039.     return(0);
  1040. }
  1041.  
  1042. int addport
  1043.   (
  1044.     ConfigRec *config
  1045.   )
  1046. {
  1047.     int i,cur,new, domlook=0,kk;
  1048.     char temp[43],*p,*rindex();
  1049.     long VSwhereis();
  1050.     struct machinfo *mp;
  1051.     DialogPtr dtemp;
  1052.     struct machinfo *Sgethost();
  1053.  
  1054.     SetCursor( watchcurs);                    /* We may be here ARPTO seconds */
  1055.  
  1056.     paramtext( config->machine, 0L, 0L, "");
  1057.                                         /* No errors and this is the session */
  1058.     ptoc(config->machine);                                    
  1059. /*
  1060. *  check for port number tacked onto machine name.
  1061. */
  1062.     if (!config->ftpwind)                    /* is it an ftp window? */
  1063.         {
  1064.         p = rindex(config->machine, ' ');    /* look for space */
  1065.         if (p) {
  1066.             i = atoi(p);
  1067.             if (i > 0)
  1068.                 config->port = i;            /* new port to try for */
  1069.             p = index(config->machine, ' ');
  1070.             if (p)
  1071.                 *p = 0;                        /* terminate string at first space */
  1072.             }
  1073.         }
  1074. /*    else config->port = 21;                    /* BYU 2.4.20 - not needed, start at ftp port */
  1075.     
  1076.     new=0;                                /* Spot for new conn # */
  1077.  
  1078.     mp = Sgethost( config->machine );
  1079.  
  1080.                     /* Make the config record count for something..... */
  1081.  
  1082.     putln("got before configrec");
  1083.     if (!mp && (config->connectionType == 0))  {    /* BYU serial */
  1084.         new = Sdomain( config->machine);
  1085.         domlook=1;
  1086.  
  1087.         mp = Slooknum(new);                /* get machine record */
  1088.         putln("after looknum");
  1089.          if (mp && config->port > 0) 
  1090.             mp->port = config->port;      /* save port to use later */
  1091.         }
  1092.     else {
  1093.  
  1094. /* 
  1095. *  When it comes to the port number to try for, if our user asked for
  1096. *  a specific port number, make sure he gets it.  Otherwise take the 
  1097. *  config file's word for it. 
  1098. */
  1099.         putln("inside else");
  1100.         if (config->ftpstate != 0)         /* BYU mod */
  1101.             config->port = 21;            /* BYU mod */
  1102.         else                            /* BYU mod */
  1103.         if (config->port == 23 && mp->port > 0)
  1104.             config->port = mp->port;        
  1105.         
  1106.         
  1107.         putln("before Snetopen");
  1108.         new = Snetopen( mp, config->port, config->connectionType);    /* BYU 2.4.15 */
  1109.  
  1110.         if (new < 0) {                                                 /* BYU 2.4.15 */
  1111.  
  1112.             if (config->connectionType == 0) {                                /* BYU 2.4.15 */
  1113.                 dtemp=GetNewDialog(ConnFalDLOG,(Ptr) 0L,(WindowPtr) -1L);    /* BYU 2.4.15 */
  1114.                 DrawDialog( dtemp);                                            /* BYU 2.4.15 */
  1115.     
  1116.                 Wait4Mouse();
  1117.                 DisposDialog( dtemp);
  1118.             }
  1119.  
  1120.             updateCursor(1);                            
  1121.             return(-1);
  1122.             } 
  1123.  
  1124.         }
  1125.  
  1126.  
  1127.     cur=numwindows;            /* Adjust # of windows and get this window's number */
  1128.     numwindows++;
  1129.  
  1130.     DoTheMenuChecks();
  1131.  
  1132.     screens[cur].lineAllow = config->lineAllow;
  1133.     screens[cur].eightbit = config->eightbit;        /* BYU 2.4.9 */
  1134.     screens[cur].forcesave = config->forcesave;        /* NCSA 2.5 */
  1135.     screens[cur].ftpwind = config->ftpwind;
  1136.     screens[cur].port=new;
  1137.     screens[cur].portNum = config->port;            /* NCSA */
  1138.     screens[cur].outlen=0;
  1139.  
  1140.     screens[cur].lmflag=0;
  1141.     for (kk=1; kk<19; kk++)
  1142.         (screens[cur]).slc[kk]=-1;
  1143.     screens[cur].slc[SLC_IP]=3;
  1144.     screens[cur].slc[SLC_EC]=127;
  1145.     screens[cur].slc[SLC_EL]=21;
  1146.     screens[cur].slc[SLC_EOF]=4;
  1147.     screens[cur].slc[SLC_ABORT]=3;
  1148.     screens[cur].slc[SLC_SUSP]=26; 
  1149.     
  1150.  
  1151.     screens[cur].vs=RSnewwindow( &config->window, config->scrollback, config->width, config->nlines,
  1152.                                   config->name, config->vtwrap, config->font, config->fsize,
  1153.                                   0, Prefs.dontclose, config->forcesave); /* NCSA 2.5 */
  1154.     screens[cur].wind=RSgetwindow( screens[cur].vs);
  1155.  
  1156.     sprintf(temp,"VS -%d- %lx (%d)",screens[cur].vs, VSwhereis(screens[cur].vs),
  1157.                                     config->scrollback);
  1158.     putln(temp);
  1159.  
  1160.     if (screens[cur].vs<0) {
  1161.         putln( "Couldn't open Virtual Screen");
  1162.         updateCursor(1);                            /* Done stalling the user */
  1163.         return(-1);
  1164.         }
  1165.  
  1166.     screens[cur].maxscroll=config->scrollback;
  1167. #ifdef TESTING
  1168.     screens[cur].termstate=DUMBTYPE;
  1169. #else
  1170.     screens[cur].termstate=VTEKTYPE;
  1171. #endif TESTING
  1172.     screens[cur].naws =0;                    /* NCSA - set default NAWS to zero */
  1173.     screens[cur].rows =config->nlines;        /* BYU 2.4.16 */
  1174.     screens[cur].bsdel=config->bsdel;
  1175.     screens[cur].name=config->name;
  1176.     screens[cur].machine=config->machine;
  1177.     screens[cur].crmap = config->crmap;
  1178.     screens[cur].tekclear= config->tekclear;
  1179.     screens[cur].ESscroll= config->clearsave;
  1180.     screens[cur].ESclear= TRUE;                /* BYU 2.4.8 - default Tek page clears screen */
  1181.     screens[cur].xfer=0;
  1182.     screens[cur].connectionType=config->connectionType;    /* BYU serial */
  1183.     screens[cur].ftpstate=config->ftpstate;    /* BYU */
  1184.     screens[cur].tektype = config->tektype;
  1185.     screens[cur].telstate=0;
  1186.     screens[cur].timing=0;
  1187.     screens[cur].curgraph=-1;            /* No graphics screen */
  1188.     screens[cur].echo=0;                /* I'm not echoing, are you? */
  1189.     screens[cur].ftpport = -1;            /* BYU - No additional FTP port opened yet */
  1190.     screens[cur].clientflags = 0;        /* BYU */
  1191.     if (config->ftpstate != 0) {        /* BYU */
  1192.       screens[cur].termstate=DUMBTYPE;    /* BYU */
  1193.       screens[cur].echo=1;                /* BYU - Echo for ftp */
  1194.       screens[cur].halfdup = 1;            /* BYU */
  1195.     } else {                            /* BYU */
  1196.       screens[cur].termstate=VTEKTYPE;    /* BYU */
  1197.       screens[cur].echo=0;                /* BYU - I'm not echoing, are you? */
  1198.       screens[cur].halfdup = config->halfdup;    /* BYU */
  1199.     }                                    /* BYU */
  1200.     screens[cur].wrap = config->vtwrap;    /* wrap mode anyone? */
  1201.     screens[cur].kblen=0;                /* nothing in the buffer */
  1202.     screens[cur].enabled=1;                /* Gotta be enabled to start with */
  1203.     screens[cur].Ittype=0;
  1204.     screens[cur].Isga=0;                /* I suppress go ahead = no */
  1205.     screens[cur].Usga=0;                /* U suppress go ahead = no */
  1206.     screens[cur].corpse=0;
  1207.     screens[cur].width= config->width;
  1208.     if (screens[cur].connectionType != 0) {        /* BYU serial - if serial connection ... */
  1209.         screens[cur].TELstop = -1;                /* BYU serial - no stopping */
  1210.         screens[cur].TELgo = -1;                /* BYU serial - no going */
  1211.         screens[cur].TELip = -1;                /* BYU serial - no Interrupting the Process */
  1212.     } else {
  1213.         screens[cur].TELstop = config->TELstop;    /* BYU serial - ^s stops */
  1214.         screens[cur].TELgo = config->TELgo;        /* BYU serial - ^q gos */
  1215.         screens[cur].TELip = config->TELip;        /* BYU serial - ^c Interrupts the Process */
  1216.     }
  1217.  
  1218.     for (i=0;i<4;i++)
  1219.         if (RSsetcolor( screens[cur].vs, i, config->red[i],
  1220.                                         config->green[i],
  1221.                                         config->blue[i]))
  1222.             putln("Trouble setting the color");
  1223.         else putln("Color set...");
  1224.  
  1225.     if ((screens[cur].connectionType == 1) && !slip_connection) {        /* BYU 2.4.15 */
  1226.         addinmenu(cur, (Str255 *) screens[cur].name, (char) 0x13);        /* BYU serial */
  1227.         screens[cur].active=0;                                            /* BYU serial */
  1228.         RSshow( screens[cur].vs);            /* BYU serial */
  1229.         SelectWindow(screens[cur].wind);    /* BYU serial */
  1230.         screens[cur].Usga=1;                /* BYU serial */
  1231.         changeport(scrn,cur);                /* BYU serial */
  1232.         liveport(scrn);                        /* BYU serial */
  1233.         }                                    /* BYU serial */
  1234.     else                                    /* BYU serial */
  1235.  
  1236.     if (domlook) {
  1237.         addinmenu(cur, (Str255 *) screens[cur].name, (char) 0x13);
  1238.         screens[cur].active = -1;
  1239.         }
  1240.     else {
  1241.         addinmenu(cur, (Str255 *) screens[cur].name, (char) 0xa5);
  1242.         screens[cur].active = 1;
  1243.         }
  1244.  
  1245.     VSscrolcontrol( screens[scrn].vs, -1, screens[scrn].ESscroll);
  1246.     updateCursor(1);                            /* Done stalling the user */
  1247. /*    netgetip( myipnum);    */            /* For Driver version, we must get our number */
  1248.     return(cur);
  1249. } /* addport */
  1250.  
  1251. void destroyport
  1252.   (
  1253.     int wind
  1254.   )
  1255. {
  1256.     int i,
  1257.         callNoWindow=0;
  1258.  
  1259.  
  1260.     SetCursor( watchcurs);                    /* We may be here a while */
  1261.  
  1262.     if (!screens[wind].corpse) {
  1263.         if (screens[wind].curgraph>-1)
  1264.             detachGraphics( screens[wind].curgraph);    /* Detach the Tek screen */
  1265.         if (screens[wind].outlen>0) {
  1266.             screens[wind].outlen=0;                        /* Kill the remaining send*/
  1267.             HUnlock( screens[wind].outhand);            /*  buffer */
  1268.             HPurge ( screens[wind].outhand);
  1269.             }
  1270.         }
  1271.  
  1272.  
  1273.     /* Get rid of the names.  We don't need them anymore */
  1274.     
  1275.     DisposPtr(screens[wind].machine);
  1276.     DisposPtr(screens[wind].name);
  1277.  
  1278.  
  1279.  
  1280.     if (FrontWindow() == screens[wind].wind)
  1281.         callNoWindow=1;
  1282.  
  1283.     RSkillwindow( screens[wind].vs);
  1284.     screens[wind].active=-5;
  1285.     for (i=wind;i<numwindows-1;i++) {
  1286.         screens[i]=screens[i+1];        /* Bump all of the pointers */
  1287.         }
  1288.     if (scrn>wind) scrn--;                /* Adjust for deleting a lower #ered screen */
  1289.  
  1290.     numwindows--;                        /* There are now fewer windows */
  1291.     extractmenu( wind);                    /* remove from the menu bar */
  1292.  
  1293.     DoTheMenuChecks();
  1294.  
  1295. /* BYU 2.4.11 - the call to "NoWindow()" changes "myfrontwindow", 
  1296.                 which is used by "updateCursor()", so we reversed 
  1297.                 the order of the following two lines.  This was 
  1298.                 causing the Mac the hang sometimes. */
  1299.     if (callNoWindow) NoWindow();    /* BYU 2.4.11 - Update cursor stuff if front window */
  1300.     updateCursor(1);                /* BYU 2.4.11 - Done stalling the user */
  1301.  
  1302. } /* destroyport */
  1303.  
  1304. void removeport
  1305.   (
  1306.     int wind
  1307.   )
  1308. {
  1309.     SetCursor( watchcurs);                    /* We may be here a while */
  1310.  
  1311.     if (screens[wind].curgraph>-1)
  1312.         detachGraphics( screens[wind].curgraph);    /* Detach the Tek screen */
  1313.     if (screens[wind].outlen>0) {
  1314.                 screens[wind].outlen=0;                /* Kill the remaining send*/
  1315.                 HUnlock( screens[wind].outhand);    /*  buffer */
  1316.                 HPurge ( screens[wind].outhand);
  1317.                 }
  1318.     if (!Prefs.dontclose)
  1319.         destroyport(wind);
  1320.     else {
  1321.         char temp[255];
  1322.         sprintf(temp, "(%s)",screens[wind].name);
  1323.         setwtitle( screens[wind].wind, temp);
  1324.  
  1325.         screens[wind].corpse=1;
  1326.         screens[wind].port = 32700;
  1327.         screens[wind].active=-5;
  1328.  
  1329.         }
  1330.     updateCursor(1);                            /* Done stalling the user */
  1331. } /* removeport */
  1332.  
  1333. int findbyWind                        /* Find screen index by Window */
  1334.   (
  1335.     GrafPtr wn
  1336.   )
  1337. {
  1338.     int i=0;
  1339.  
  1340.     while((i<numwindows) && (wn!=screens[i].wind)) i++;
  1341.     if (i>=numwindows) return(-1);
  1342.     return(i);
  1343. }
  1344.  
  1345. int findbyVS                        /* Find screen index by VS Number */
  1346.   (
  1347.     int vs
  1348.   )
  1349. {
  1350.     int i=0;
  1351.  
  1352.     while((i<numwindows) && (vs!=screens[i].vs)) i++;
  1353.     if (i>=numwindows) return(-1);
  1354.     return(i);
  1355. }
  1356.  
  1357. int isEightBit(int vs) {            /* BYU 2.4.12 */
  1358.     int i = findbyVS(vs);            /* BYU 2.4.12 */
  1359.     if (i>=numwindows) return(0);    /* BYU 2.4.12 */
  1360.     return(screens[i].eightbit);    /* BYU 2.4.12 */
  1361. }                                    /* BYU 2.4.12 */
  1362.  
  1363. void ERR                /* Error routine for BKGR/ICMP/etc....*/
  1364.   (
  1365.     int num
  1366.   )
  1367. {
  1368.     char temp[80],*dummy;
  1369.  
  1370.     dummy=strncpy( &temp[1],neterrstring(num),78);
  1371.     temp[79]='\0';                        /* Compensate for error in strncopy */
  1372.     temp[0]= (unsigned char)strlen(&temp[1]);
  1373.     paramtext(0L,0L,0L,&temp[1]);            /* Load the error record field */
  1374.     putln( &temp[1]);
  1375. }
  1376.  
  1377. void xferstart                    /* Called at start of FTP */
  1378.   (
  1379.     void
  1380.   )
  1381. {
  1382.     xferon=1;
  1383.     updateCursor(1);
  1384. }
  1385.  
  1386. void xferdone                    /* Called at end of FTP */
  1387.   (
  1388.     void
  1389.   )
  1390. {
  1391.     xferon=0;
  1392.     updateCursor(1);
  1393. }
  1394.  
  1395. void setgraphcurs                    /* Called at start of gin */
  1396.   (
  1397.     void
  1398.   )
  1399. {
  1400.     putln("Graphics INput mode entered");
  1401.     ginon=1;
  1402.     updateCursor(1);
  1403. }
  1404.  
  1405. void unsetgraphcurs                    /* Called at start of gin */
  1406.   (
  1407.     void
  1408.   )
  1409. {
  1410.     ginon=0;
  1411.     updateCursor(1);
  1412. }
  1413.  
  1414. int decodeIPnum
  1415.   (
  1416.     char *s,
  1417.     unsigned char *myipnum
  1418.   )
  1419. {
  1420.     int i, node, hi, low;
  1421.     char temp[50];
  1422.  
  1423.     for (i=0; i<4; i++) myipnum[i]=0;
  1424.     i=0;
  1425.     
  1426.     if (!EtherNet)
  1427.         getATaddress( &hi, &low, &node);
  1428.  
  1429.     while((*s) && (i<4) ) {
  1430.         switch( *s) {
  1431.             case '0':
  1432.             case '1':
  1433.             case '2':
  1434.             case '3':
  1435.             case '4':
  1436.             case '5':
  1437.             case '6':
  1438.             case '7':
  1439.             case '8':
  1440.             case '9':
  1441.                 myipnum[i]= myipnum[i] *10 + (*s-'0');
  1442.                 break;
  1443.             case '.':
  1444.                 i++;
  1445.                 break;
  1446.             case 'H':
  1447.             case 'h':
  1448.                 myipnum[i]=hi;
  1449.                 break;
  1450.             case 'L':
  1451.             case 'l':
  1452.                 myipnum[i]=low;
  1453.                 break;
  1454.             case 'N':
  1455.             case 'n':
  1456.                 myipnum[i]=node;
  1457.                 break;
  1458.             default:
  1459.                 break;
  1460.             }
  1461.         s++;
  1462.         }
  1463.     
  1464.     sprintf( temp," IPNUM= %d.%d.%d.%d", (int) myipnum[0], (int) myipnum[1], (int) myipnum[2],
  1465.                                          (int) myipnum[3]);
  1466.     putln(temp);
  1467.     
  1468.     if (i<3) return( 1);
  1469.         else return( 0);
  1470. }
  1471.  
  1472. /*    CheckConfig (dynamic, dIP, useMask, dMask)
  1473.  *
  1474.  *        checks the configuration described by IP and Mask strings.  If it is OK,
  1475.  *            it returns (0).  If it is bad, it displays a message and returns (1)
  1476.  */
  1477. int CheckConfig
  1478.   (
  1479.     int dynamic,
  1480.     Handle dIP,
  1481.     int useMask,
  1482.     Handle dMask
  1483.   )
  1484. {
  1485.     DialogPtr dtemp;
  1486.     char temp[256];
  1487.     short item;
  1488.     int error=0;
  1489.     long ltemp;
  1490.  
  1491.     if (!dynamic) {                /* Check IP NUmber if appropriate */
  1492.         GetIText( dIP, temp);
  1493.         temp[temp[0] + 1]=0;            /* be safe for the wonderful sscanf */
  1494.     
  1495.         if (decodeIPnum(&temp[1], (unsigned char *) <emp)) {
  1496.             error=1;
  1497.  
  1498.             dtemp=GetNewDialog( BadIPDLOG,(Ptr) 0L,(WindowPtr) -1L);
  1499.             ModalDialog((ModalFilterProcPtr) modalProc, &item);
  1500.             DisposDialog(dtemp);
  1501.             }
  1502.         }
  1503.  
  1504.     if (useMask) {                /* Check Subnet Mask if appropriate */
  1505.         GetIText( dMask, temp);
  1506.         temp[temp[0] + 1] = 0;            /* be safe for the wonderful sscanf */
  1507.  
  1508.         if (temp[0]!=8 || (sscanf(&temp[1], "%lx", <emp)!=1) ) {
  1509.             error=1;
  1510.  
  1511.             dtemp=GetNewDialog( BadMaskDLOG,(Ptr) 0L,(WindowPtr) -1L);
  1512.             ModalDialog((ModalFilterProcPtr) modalProc, &item);
  1513.             DisposDialog(dtemp);
  1514.             }
  1515.         }
  1516.     return(error);
  1517. }
  1518.  
  1519. /*
  1520.  * PromptIP - this is one HUGE procedure, but I have not come up with an easy way
  1521.  *    to break it down.  It allows you to change all of the network parameters....
  1522.  */
  1523.  
  1524. int PromptIP
  1525.   (
  1526.     int dynam
  1527.   )
  1528. {
  1529.  
  1530. #define GetStrRes(x)    (Str255 **)GetResource('STR ',x);
  1531.  
  1532.     DialogPtr dtemp;
  1533.     Str255 *ptemp,nstring;
  1534.     Str255 **hostR,**ipR, **maskR;
  1535.     Str255 **fileR, *ftemp;                /* NCSA 2.5: Capture session file */
  1536.     Rect dBox;
  1537.     Handle dynIP,statIP,useMask,dHand, dIP, dMask;
  1538.     int olddynam;
  1539.     int mask=0,terr,badconfig=1, enteredbad;
  1540.     short dItem;
  1541.     
  1542.     dtemp=GetNewDialog(GetParmDLOG,(Ptr) 0L,(WindowPtr) -1L); /* Get the dialog to use */
  1543.  
  1544.     UItemAssign( dtemp, 11, (int (*)()) OutlineItem);
  1545.  
  1546.     ipR=GetStrRes(IPnumSTR);                /* Was there an IP Number before */
  1547.  
  1548.     if (ipR!=0L) {                            /* If So...*/
  1549.         GetDItem(dtemp,GetParmIP,&dItem,&dHand,&dBox);    /* Get the dialog item */
  1550.         HLock((Handle) ipR);                            /* Lock the string in */
  1551.  
  1552.         SetIText(dHand, (Str255) *ipR);                    /* Set the item's text to the old 1*/
  1553.         SelIText(dtemp,GetParmIP,0,32767);                /* And select it */
  1554.         HUnlock((Handle) ipR);                            /* Unlock the string */
  1555. #ifdef OLDM
  1556.         RmveResource(ipR);                    /* Remove the old rotting number */
  1557. #endif
  1558.         putln("Reading previous IP Resource");
  1559.         }
  1560.     else if (KIP) dynam=1;                    /* Default to dynamic if KIP + no res */
  1561.  
  1562.  
  1563.     fileR=GetStrRes( FileSTR);                /* NCSA 2.5 */
  1564.     if (fileR!=0L) {                        /* NCSA 2.5 */
  1565.         GetDItem(dtemp,GetCaptureName,&dItem,&dHand,&dBox);    /* NCSA 2.5 */
  1566.         HLock((Handle) fileR);                    /* NCSA 2.5 */
  1567.                                                 /* NCSA 2.5 */    
  1568.         SetIText(dHand, (Str255) *fileR);        /* NCSA 2.5 */
  1569.                                                 /* NCSA 2.5 */    
  1570.         HUnlock((Handle) fileR);                /* NCSA 2.5 */
  1571.         putln("Reading previous Capture File Resource");    /* NCSA 2.5 */
  1572.         }                                        /* NCSA 2.5 */
  1573.  
  1574.     hostR=GetStrRes( HostSTR);        /* Was there a default host */
  1575.     if (hostR!=0L) {                            /* If So...*/
  1576.         GetDItem(dtemp,GetParmHOST,&dItem,&dHand,&dBox);    /* Get the dialog item */
  1577.         HLock((Handle) hostR);                    /* Lock the string in */
  1578.  
  1579.         SetIText(dHand, (Str255) *hostR);        /* Set the item's text to the old 1*/
  1580.  
  1581.         HUnlock((Handle) hostR);                /* Unlock the string */
  1582.         putln("Reading previous Default Dest. Resource");
  1583.         }
  1584.  
  1585.     maskR=GetStrRes( MaskSTR );
  1586.     if (maskR!=0L) {                            /* If So...*/
  1587.         GetDItem(dtemp,GetParmMASK,&dItem,&dHand,&dBox);    /* Get the dialog item */
  1588.         HLock((Handle) maskR);                        /* Lock the string in */
  1589.  
  1590.         SetIText(dHand, (Str255) *maskR);            /* Set the item's text to the old 1*/
  1591.  
  1592.         HUnlock((Handle) maskR);                    /* Unlock the string */
  1593.  
  1594.         if ( mynetmask!=defmask ) mask=1;        /* Is the mask custom? */
  1595.  
  1596.         putln("Reading previous Mask Resource");
  1597.         }
  1598.  
  1599.     olddynam = dynam;
  1600.  
  1601.     dItem=0;
  1602.     GetDItem(dtemp,GetParmStat,&dItem,&statIP,&dBox);    /* Get the IP # handle */
  1603.  
  1604.     dItem=0;
  1605.     GetDItem(dtemp,GetParmKDyn,&dItem,&dynIP,&dBox);    /* Get the Dynam Handle */
  1606.  
  1607.     dItem=0;
  1608.     GetDItem(dtemp,GetParmUseM,&dItem,&useMask,&dBox);    /* Get the Mask Handle */
  1609.  
  1610.     dItem=0;
  1611.     GetDItem(dtemp,GetParmIP,&dItem,&dIP,&dBox);        /* Get the IP TE Handle */
  1612.  
  1613.     dItem=0;
  1614.     GetDItem(dtemp,GetParmMASK,&dItem,&dMask,&dBox);    /* Get the Mask TE Handle */
  1615.  
  1616.     if (!(KIP || EtherNet)) {
  1617.         HiliteControl((ControlHandle) dynIP,255);    /* Dont even think of dynam */
  1618.         dynam = 0;
  1619.         }
  1620.  
  1621.     SetCtlValue((ControlHandle) dynIP,dynam);                /* Set up the controls */
  1622.  
  1623.     SetCtlValue((ControlHandle) statIP, !dynam);            /* Kip/RARP can have dynamic */
  1624.  
  1625.     SetCtlValue((ControlHandle) useMask, mask);                /* No Mask to start */
  1626. #ifdef MAYBELATER
  1627.     enteredbad = CheckConfig( dynam, dIP, mask, dMask);
  1628.                                             /* We can't cancel if we have a bad start */
  1629. #else
  1630. #pragma unused(enteredbad)
  1631. #endif
  1632.     while( badconfig) {
  1633.         dItem=0;
  1634.         while((dItem> 2) || (dItem==0)) {        /* loop till done */
  1635.             ModalDialog((ModalFilterProcPtr) modalProc ,&dItem); /* Get an event */
  1636.             if (dItem==GetParmIP)  
  1637.                     if (dynam) dItem = GetParmStat;
  1638.             if (dItem==GetParmStat) { dynam=0;                    /* They want to tell me */
  1639.                             SetCtlValue((ControlHandle) dynIP,dynam);
  1640.                             SetCtlValue((ControlHandle) statIP, !dynam);
  1641.                         }
  1642.             if (dItem==GetParmKDyn) { dynam=1;                    /* I should figure it out */
  1643.                             SetCtlValue((ControlHandle) dynIP,dynam);
  1644.                             SetCtlValue((ControlHandle) statIP, !dynam);
  1645.                         }
  1646.             if (dItem==GetParmMASK) 
  1647.                     if (!mask) dItem=GetParmUseM;
  1648.             if (dItem==GetParmUseM) {mask=!mask;
  1649.                             SetCtlValue((ControlHandle) useMask,mask);
  1650.                         }
  1651.             }
  1652.     
  1653.         if (dItem == 1) {
  1654.             DisposDialog(dtemp);                        /* Get rid of dialog */
  1655.             return(olddynam);
  1656.             }
  1657.         badconfig=CheckConfig( dynam, dIP, mask, dMask);
  1658.         }            /* End of While Badconfig */
  1659.  
  1660.     if (SettingsFile==-1) {
  1661.         DisposDialog(dtemp);
  1662.         return(dynam);
  1663.         }
  1664.  
  1665.  
  1666.     if (ipR ==0L) {
  1667.         putln("Making new IP number resource");
  1668.         ipR=(Str255 **)NewHandle(256L);        /* Get a temp handle */
  1669.         if (ipR==0L) putln("I can't get any space");
  1670.         addresource((Handle) ipR,'STR ',256,"IP Number");
  1671.         if ((terr=ResError())!=0) {
  1672.             sprintf(&nstring,"Error in addresource. (%d)",terr);
  1673.             putln(&nstring);
  1674.             }
  1675.         }
  1676.  
  1677.     HLock((Handle) ipR);                    /* Lock it down */
  1678.     ptemp=*ipR;                                /* a pointer for sanity*/
  1679.  
  1680.     GetIText(dIP, (Str255) ptemp);                /* Get the IP Number fm the TE */
  1681.     (*ptemp)[(*ptemp)[0] + 1] = 0;                /* be on the scanf safe side */
  1682.  
  1683.     if (dynam) (*ptemp)[0]=0;
  1684.     else 
  1685.         if (0==decodeIPnum( &(*ptemp)[1], myipnum) )
  1686.                 putln("Got a successful IP Number");
  1687.  
  1688.     HUnlock((Handle) ipR);
  1689.     ChangedResource((Handle) ipR);
  1690.     UpdateResFile(HomeResFile((Handle) ipR));    /* now it is saved, process it*/
  1691.  
  1692. /******/
  1693.  
  1694.  
  1695.     if (fileR ==0L) {                                    /* NCSA 2.5 */
  1696.         putln("Making new Capture File resource");        /* NCSA 2.5 */
  1697.         fileR=(Str255 **)NewHandle(256L);                /* NCSA 2.5 */
  1698.         if (fileR==0L) putln("I can't get any space");    /* NCSA 2.5 */
  1699.         addresource((Handle) fileR,'STR ',FileSTR,"CaptureFile");    /* NCSA 2.5 */
  1700.         if ((terr=ResError())!=0) {                                /* NCSA 2.5 */
  1701.             sprintf(&nstring,"Error in addresource. (%d)",terr);    /* NCSA 2.5 */
  1702.             putln(&nstring);                                    /* NCSA 2.5 */
  1703.             }                                            /* NCSA 2.5 */
  1704.         }                                                /* NCSA 2.5 */
  1705.  
  1706.     if (hostR ==0L) {
  1707.         putln("Making new Host resource");
  1708.         hostR=(Str255 **)NewHandle(256L);        /* Get a temp handle */
  1709.         if (hostR==0L) putln("I can't get any space");
  1710.         addresource((Handle) hostR,'STR ',257,"Default Host");
  1711.         if ((terr=ResError())!=0) {
  1712.             sprintf(&nstring,"Error in addresource. (%d)",terr);
  1713.             putln(&nstring);
  1714.             }
  1715.         }
  1716.  
  1717.     HLock((Handle) hostR);                                /* Lock it down */
  1718.     ptemp=*hostR;                                /* a pointer for sanity*/
  1719.  
  1720.     GetDItem(dtemp,GetParmHOST,&dItem,&dHand,&dBox);        /* Get the Default Host */
  1721.     GetIText(dHand, (Str255) ptemp);
  1722.  
  1723.     movmem( ptemp, defaultd,256);                /* Make a copy for later */
  1724.     p2cstr((StringPtr) defaultd);
  1725.  
  1726.     HUnlock((Handle) hostR);
  1727.     ChangedResource((Handle) hostR);
  1728.     UpdateResFile(HomeResFile((Handle) hostR));
  1729.  
  1730.  
  1731.     HLock((Handle) fileR);                        /* NCSA 2.5 */
  1732.     ftemp=*fileR;                                /* NCSA 2.5 */
  1733.     GetDItem(dtemp,GetCaptureName,&dItem,&dHand,&dBox);    /* NCSA 2.5 */
  1734.     GetIText(dHand, (Str255) ftemp);            /* NCSA 2.5 */
  1735.     HUnlock((Handle) fileR);                    /* NCSA 2.5 */
  1736.     ChangedResource((Handle) fileR);            /* NCSA 2.5 */
  1737.     UpdateResFile(HomeResFile((Handle) fileR));    /* NCSA 2.5 */
  1738.  
  1739.  
  1740. /******/
  1741.  
  1742.     if ((maskR ==0L) || (GetHandleSize((Handle) maskR) < 9)) {        /* BYU 2.4.7 */
  1743.         maskR=(Str255 **)NewHandle(256L);        /* Get a temp handle */
  1744.         putln("Making new Mask resource");
  1745.         if (maskR==0L) putln("I can't get any space");
  1746.         addresource((Handle) maskR, 'STR ', MaskSTR, "Network Mask");
  1747.         if ((terr=ResError())!=0) {
  1748.             sprintf( &nstring, "Error in addresource. (%d)", terr);
  1749.             putln(&nstring);
  1750.             }
  1751.         }
  1752.  
  1753.     HLock((Handle)maskR);                                /* Lock it down */
  1754.     ptemp=*maskR;                                /* a pointer for sanity*/
  1755.  
  1756.     GetIText(dMask, (Str255) ptemp);                /* Get the Mask from the Dialog */
  1757.  
  1758.     if (mask) { putln("using custom mask");
  1759.                 cmask=1;
  1760.                 } else cmask=0;
  1761.     (*ptemp)[(*ptemp)[0] + 1] = '\0';            /* terminate for sscanf */
  1762.     
  1763. /* BYU 2.4.7 - We want the operator specified mask to take precedence 
  1764.    over any default settings.
  1765. */
  1766. #if 1
  1767.     if ((*ptemp)[0] == 8) {                                    /* BYU 2.4.7 */
  1768.         sscanf((char *) ptemp + 1, "%lx", &mynetmask);        /* BYU 2.4.7 */
  1769.         cmask=1;                                            /* BYU 2.4.7 */
  1770.     } else {                                                /* BYU 2.4.7 */
  1771. #else
  1772.     if (( 1!=sscanf((char *) ptemp + 1, "%lx", &mynetmask))/* || (!mask)*/) {        /* BYU 2.4.7 */
  1773. #endif
  1774.         (*ptemp)[0] = 0;                    /* Make it remain default */
  1775.         (*ptemp)[1] = ' ';
  1776.         putln( "Default mask used, saved mask cleared....");
  1777.         }
  1778.  
  1779.     HUnlock((Handle) maskR);
  1780.     ChangedResource((Handle) maskR);
  1781.     UpdateResFile(HomeResFile((Handle) maskR));
  1782. /******/
  1783.  
  1784.     DisposDialog(dtemp);                        /* Get rid of dialog */
  1785.  
  1786.     return(dynam);                                /* Return with the status of */
  1787.                                                 /* Dynamic or Static IP */
  1788.   } /* PromptIP */
  1789.  
  1790. /*
  1791.  *    Get a dynamic IP Number..... this should be done only if you are Crofted
  1792.  */
  1793. int DynamIP
  1794.   (
  1795.     char *ipnum
  1796.   )
  1797. {
  1798.     if (!KIP) {
  1799.         putln("You can't use dynamic IP Numbers without Croft!!");
  1800.         return(-1);
  1801.         }
  1802.     putln("Obtaining a dynamic IP Number");
  1803.  
  1804.     if (KIPgetdynam(&KIPserver, (long *) ipnum) <0) {
  1805.         OtherError("Error obtaining dynamic IP #.","Dynamic addressing not available");
  1806.         putln("dynamic IP get failed ");
  1807.         return(-1);
  1808.         }
  1809.  
  1810.     return(0);
  1811. }
  1812.  
  1813. /*
  1814.  *    Register your IP Number..... this need be done only if you are Crofted
  1815.  */
  1816. int RegIP
  1817.   (
  1818.     char *ipnum
  1819.   )
  1820. {
  1821. #if 1                                                            /* BYU 2.4.11 */
  1822.     if (EtherNet) {                                                /* BYU 2.4.11 */
  1823.         putln("You don't need to register on ethernet....");    /* BYU 2.4.11 */
  1824. #else                                                            /* BYU 2.4.11 */
  1825.     if (!KIP) {
  1826.         putln("You don't need to register if you aren't using Croft....");
  1827. #endif                                                            /* BYU 2.4.11 */
  1828.         return(0);
  1829.         }
  1830.     putln("Registering IP Number to the network");
  1831.     if (KIPregister(ipnum) <0) {
  1832.         putln("Registration failed!!");
  1833.         return(-1);
  1834.         }
  1835.     return(0);
  1836. }
  1837.  
  1838. void setnetconfigs
  1839.   (
  1840.     char *ipnum,
  1841.     long *netmask
  1842.   )
  1843. {
  1844.     char sbuf[80];
  1845.     sprintf(sbuf,"%lx is mask",*netmask);
  1846.     putln(sbuf);
  1847.  
  1848.     netsetip(ipnum);                /* Here is your number */
  1849.  
  1850.     netsetmask((unsigned char *) netmask); /* And your network type */
  1851. }
  1852.  
  1853. /*
  1854.  *    initipnum - Initialize the IP number, and check it and the other wonderful
  1855.  *        things associated (mask,ip #, def host). Button forces the PromptIP dialog.
  1856.  *
  1857.  *  Thanks to Ric Anderson from the University of Arizona for the setvol patches to
  1858.  *  make the system folder work right.
  1859.  */
  1860.  
  1861. int initipnum
  1862.   (
  1863.     int button
  1864.   )
  1865. {
  1866.     Str255 *tempp,**temph;
  1867.     int error=0,dynam=0;
  1868.     short refnum;
  1869.     long ns;
  1870.     char *myDir;
  1871.     short myVRef;
  1872.     WDPBRec theWD;
  1873.     OSErr     err=0;
  1874.     
  1875. /*    strncpy (files_name, name, size);
  1876.     files_name[size] = 0; */
  1877.  
  1878.  
  1879.  
  1880.   /* look for an existing settings file. The usual search path
  1881.     for this will include the current folder and the system folder,
  1882.     unless they're on different volumes (see tech note 77). */
  1883.  
  1884.     myDir = (char *)NewPtr(255);
  1885.     setmydir(); /* first, try the application folder */
  1886.     SettingsFile=openrfperm("NCSA Telnet Settings",0,fsRdWrShPerm);    /* BYU - Open the Settings file shared. */
  1887.     if (SettingsFile == - 1)
  1888.       {
  1889.         sysdir(); /* in case it's on a different volume */
  1890.         SettingsFile=openrfperm("NCSA Telnet Settings",0,fsRdWrShPerm);    /* BYU - Open the Settings file shared. */
  1891.       } /* if */
  1892.  
  1893.     if (SettingsFile == - 1)
  1894.         {
  1895.  
  1896.         GetVol(myDir,&myVRef);    
  1897.         myDir[myDir[0]+2] = 0;        
  1898.         strcat(myDir,"System Folder:Preferences");
  1899.         myDir[myDir[0]+1] = ':';
  1900.         myDir[0] += (strlen("System Folder:Preferences")+1);
  1901.         
  1902.  
  1903.         putln("the dir is:");
  1904.         putln(myDir);
  1905.  
  1906.         theWD.ioCompletion = NULL;
  1907.         theWD.ioNamePtr = myDir;
  1908.         theWD.ioVRefNum = 0;
  1909.         theWD.ioWDDirID = 0;
  1910.         err = PBHSetVol (&theWD, false);
  1911.         SettingsFile=openrfperm("NCSA Telnet Settings",0,fsRdWrShPerm);    /* BYU - Open the Settings file shared. */
  1912.         
  1913.         }
  1914.  
  1915.  
  1916.     DisposPtr(myDir);
  1917.     if (SettingsFile == -1 )
  1918.       {
  1919.       /* no settings file anywhere -- create one in the system folder. */
  1920.     /*    sysdir(); */
  1921.         create("NCSA Telnet Settings", theWorld.sysVRefNum, 'NCSA', 'IPNO');
  1922.         createresfile("NCSA Telnet Settings");    /* Make a new one if it is not there .... */
  1923.         SettingsFile=openrfperm("NCSA Telnet Settings",0,fsRdWrShPerm);    /* BYU - Open the Settings file shared. */
  1924.       } /* if */
  1925.     setmydir();        /* set back to default dir */
  1926.     
  1927.   /* Initialize the default host */
  1928.     if ((defaultd=(Str255 *)NewPtr(256)) ==0L) {
  1929.         putln("Oops, no memory at all");
  1930.         quit();
  1931.         } else
  1932.             (*defaultd)[0]=0;                            /* Default to no host */
  1933.  
  1934.     temph=(Str255 **)GetResource('STR ',HostSTR);
  1935.     if (temph!=0L) {
  1936.         HLock((Handle) temph);                            /* This remains locked */
  1937.         movmem( *temph, defaultd,256);
  1938.         p2cstr((StringPtr) defaultd);
  1939.         HUnlock((Handle) temph);
  1940.         } else                                    /* BYU serial - Use it .... */
  1941.             strcpy((char *) defaultd,"");        /* BYU serial - Default to no host */
  1942.  
  1943.     if (EtherNet == -99)            /* Return on Driver TCP */
  1944.         return(1);
  1945.         
  1946.     if (!EtherNet)
  1947.       {
  1948.         OSErr err;
  1949.         err = OpenDriver("\p.MPP", &refnum);
  1950.         if (err == 0)
  1951.             putln("MPP AOk");
  1952.         else
  1953.           {
  1954.             DialogPtr dtemp;
  1955. /*            short item;                                            /* BYU 2.4.15 */
  1956.  
  1957.             putln("MPP Bad");
  1958.           /* following sequence is copied from atopen in atalk.c */
  1959.             if (err == -97 || err == -98)
  1960.                 ParamText(0L, 0L, 0L,
  1961.                     "\pYou forgot to turn on AppleTalk in the Chooser");
  1962.             else if (err == -192)
  1963.                 ParamText(0L, 0L, 0L, "\pCouldnâ•’t find â•˜atplâ•’ resource");
  1964.             else
  1965.                 ParamText(0L, 0L, 0L, "\pUnknown Error");
  1966.             dtemp = GetNewDialog(302, (Ptr) 0L, (WindowPtr) -1L);
  1967. #if 1                                                            /* BYU 2.4.15 */
  1968.             DrawDialog(dtemp);                                    /* BYU 2.4.15 */
  1969.             WaitSeconds(5);                                        /* BYU 2.4.15 */
  1970. #else                                                            /* BYU 2.4.15 */
  1971.             ModalDialog(0L, &item);
  1972. #endif                                                            /* BYU 2.4.15 */
  1973.             DisposDialog(dtemp);
  1974. /*            quit();                                                /* BYU 2.4.15 */
  1975.           }
  1976.       /* Check if KIP is the Gateway if so load number */
  1977.         if ( KIPfindgate(&KIPserver)>0)
  1978.           {
  1979.             putln("Croft Gateway is online!");        /* BYU */
  1980.             KIP=1;            /* we have a KIP Croft Gateway */
  1981.             KIPgetns(&KIPserver, &ns);
  1982.             if (ns !=0) Ssetns((unsigned char *) &ns);
  1983.           }
  1984.       }
  1985.     else
  1986.         KIP = 0;
  1987.   /* Initialize the IP Number */
  1988.     temph = (Str255 **)GetResource('STR ',IPnumSTR);
  1989.     if (temph!=0L) {
  1990.         HLock((Handle) temph);                            /* lock for string ref. */
  1991.         tempp=*temph;
  1992.  
  1993.         (*tempp)[(*tempp)[0] + 1]=0;
  1994.         error=decodeIPnum(&(*tempp)[1], myipnum);
  1995.  
  1996.         if (error) {
  1997.             if (EtherNet) {                    /* Dynamic if Ether and no IP Number */
  1998.                 strncpy(myipnum,"RARP",4);
  1999.                 dynam=1;
  2000.                 error=0;
  2001.                 }
  2002.             else if (KIP) {
  2003.                 DynamIP(myipnum);            /* Dynamic if KIP and no IP number */
  2004.                 dynam=1;
  2005.                 error=0;
  2006.                 }
  2007.             else  error=1;                /* Error  if !KIP and  "" ""       */
  2008.             }
  2009.         HUnlock((Handle) temph);            /* Get rid of old number */
  2010.         }
  2011.     else error=1;                            /* error set by lack of resource */
  2012.  
  2013.                         /* Set up our default masking, given the IP number */
  2014.  
  2015.     if (userlevel >2) {
  2016.         if (!dynam) {
  2017.             if (!KIP) error=1;
  2018.             else {
  2019.                 dynam=1;
  2020.                 DynamIP(myipnum);
  2021.                 }
  2022.             }
  2023.         }
  2024.  
  2025.     if (!(myipnum[0] & 0x80))
  2026.             defmask=0xff000000;                        /* Class A */
  2027.         else if ( (myipnum[0] & 0xC0 )==0x80)
  2028.             defmask=0xffff0000;                        /* Class B */
  2029.         else if ( (myipnum[0] & 0xC0 )==0xC0)
  2030.             defmask=0xffffff00;                        /* Class C */
  2031.  
  2032.     temph=(Str255 **)GetResource('STR ',MaskSTR);    /* Get the current mask */
  2033.     if (temph!=0L) {
  2034.         HLock((Handle) temph);                        /* Lock for string ref. */
  2035.         tempp=*temph;
  2036.         (*tempp)[(*tempp)[0] + 1] = '\0';            /* terminate for scanf */
  2037.         }
  2038.     cmask=1;
  2039. #if 1
  2040.     if (temph!=0L /*&& tempp[0] == 8*/) {                /* BYU 2.4.7 */
  2041.         sscanf((char *) tempp + 1,"%lx",&mynetmask);    /* BYU 2.4.7 */
  2042.     } else {                                            /* BYU 2.4.7 */
  2043. #else
  2044.     if (temph==0L || tempp[0] != 8 ||                            /* BYU 2.4.7 */
  2045.         (1!=sscanf((char *) tempp + 1,"%lx",&mynetmask))) {        /* BYU 2.4.7 */
  2046. #endif
  2047.             mynetmask=defmask;                    /* Default masks... */
  2048.             cmask=0;
  2049.             }
  2050.  
  2051.     if (temph!=0L) HUnlock((Handle) temph);        /* Ok, I admit this seq. has to go */
  2052.  
  2053.     if (error) putln("error is set");
  2054.     if (button) putln("button is set");
  2055.  
  2056.     dynamic = dynam;
  2057.  
  2058.     if ( (error || button) && userlevel<2) {
  2059.         putln("Prompting for IP Number");
  2060.  
  2061.         /* if (ResError()!=-192)
  2062.             ERRWarn(800);        Can't Load Existing Resource, out of space */
  2063.  
  2064.         if ( PromptIP( dynam)) {
  2065.             if (EtherNet)
  2066.                 strncpy(myipnum,"RARP",4);
  2067.             else 
  2068.                 DynamIP(myipnum);
  2069.             if (!(myipnum[0] & 0x80))
  2070.                     defmask=0xff000000;                        /* Class A */
  2071.                 else if ( (myipnum[0] & 0xC0 )==0x80)
  2072.                     defmask=0xffff0000;                        /* Class B */
  2073.                 else if ( (myipnum[0] & 0xC0 )==0xC0)
  2074.                     defmask=0xffffff00;                        /* Class C */
  2075.  
  2076.             if (!cmask) mynetmask=defmask;
  2077.  
  2078.             dynamic=1;
  2079.             }
  2080.         else dynamic=0;
  2081.         }
  2082.     else if (error) quit();
  2083.  
  2084.     setnetconfigs( myipnum,  &mynetmask);
  2085.     if (RegIP(myipnum))
  2086.         reconfigNetwork(1);
  2087.     return(0);
  2088. } /* initipnum */
  2089.  
  2090. /*
  2091. *  special dialog for the driver version.
  2092. *  This one only prompts for default host and nothing else.
  2093. *  Much of the appearance of the dialog is retained so that the user can switch
  2094. *  versions easily.
  2095. */
  2096. int driverconf
  2097.   (
  2098.     void
  2099.   )
  2100. {
  2101. #define GetStrRes(x)    (Str255 **)GetResource('STR ',(x));
  2102.  
  2103.     DialogPtr dtemp;
  2104.     Str255 *ptemp;
  2105.     Str255 **hostR;
  2106.     Rect dBox;
  2107.     Handle dHand;
  2108.     int terr;
  2109.     short dItem;
  2110.     Str255 **fileR;                    /* NCSA 2.5: handle to file name */
  2111.     Str255 *ftemp;                    /* NCSA 2.5: pointer for sanity */
  2112.     
  2113.     dtemp=GetNewDialog( GetDefDLOG,(Ptr) 0L,(WindowPtr) -1L);    /* Bring on the box */
  2114.  
  2115.  
  2116.     hostR=GetStrRes( HostSTR);        /* Was there a default host */
  2117.     fileR=GetStrRes( FileSTR);        /* NCSA 2.5: get capture file name */
  2118.  
  2119.  
  2120.     if (fileR!=0L) {                            /* NCSA 2.5: handle capture file */
  2121.         GetDItem(dtemp,8,&dItem,&dHand,&dBox);    /* NCSA 2.5: get the name */
  2122.         HLock((Handle) fileR);                    /* NCSA 2.5 */
  2123.                                                 /* NCSA 2.5 */
  2124.         SetIText(dHand, (Str255) *fileR);        /* NCSA 2.5 */
  2125.     /*    SelIText(dtemp,6,0,1000); */            /* NCSA 2.5 */
  2126.         HUnlock((Handle) fileR);                /* NCSA 2.5 */
  2127.         putln("Reading previous Default Dest. Resource");    /* NCSA 2.5 */
  2128.         }                                        /* NCSA 2.5 */
  2129.  
  2130.  
  2131.     if (hostR!=0L) {                            /* If So...*/
  2132.         GetDItem(dtemp,6,&dItem,&dHand,&dBox);    /* Get the dialog item */
  2133.         HLock((Handle) hostR);                    /* Lock the string in */
  2134.  
  2135.         SetIText(dHand, (Str255) *hostR);        /* Set the item's text to the old 1*/
  2136.         SelIText(dtemp,6,0,1000);
  2137.         HUnlock((Handle) hostR);                /* Unlock the string */
  2138.         putln("Reading previous Default Dest. Resource");
  2139.         }
  2140.     
  2141.  
  2142.     UItemAssign( dtemp, 7, (int (*)()) OutlineItem);
  2143.         
  2144.     dItem = 3;
  2145.     while (dItem> 2)     /* cancel == 1, OK == 2 */
  2146.         ModalDialog((ModalFilterProcPtr) modalProc, &dItem);
  2147.  
  2148.     if (SettingsFile==-1 || dItem == 2) {
  2149.         DisposDialog(dtemp);
  2150.         return(0);
  2151.         }
  2152.         
  2153.     if (hostR ==0L) {
  2154.         putln("Making new Host resource");
  2155.         hostR=(Str255 **)NewHandle(256L);        /* Get a temp handle */
  2156.         if (hostR==0L) putln("I can't get any space");
  2157.         addresource((Handle) hostR,'STR ',HostSTR,"Default Host");
  2158.         if ((terr=ResError())!=0) {
  2159.             putln("Error in addresource");
  2160.             }
  2161.         }
  2162.  
  2163.  
  2164.     if (fileR ==0L) {                                    /* NCSA 2.5 */
  2165.         putln("Making new Capture File resource");        /* NCSA 2.5 */
  2166.         fileR=(Str255 **)NewHandle(256L);                /* NCSA 2.5 */
  2167.         if (fileR==0L) putln("I can't get any space");    /* NCSA 2.5 */
  2168.         addresource((Handle) fileR,'STR ',FileSTR,"Capture File");    /* NCSA 2.5 */
  2169.         if ((terr=ResError())!=0) {                        /* NCSA 2.5 */
  2170.             putln("Error in addresource");                /* NCSA 2.5    */
  2171.             }                                            /* NCSA 2.5 */
  2172.         }                                                /* NCSA 2.5 */
  2173.  
  2174.  
  2175.  
  2176.     HLock((Handle) hostR);                        /* Lock it down */
  2177.     ptemp=*hostR;                                /* a pointer for sanity*/    
  2178.     GetDItem(dtemp,6,&dItem,&dHand,&dBox);        /* Get the Default Host */
  2179.     GetIText(dHand, (Str255) ptemp);
  2180.     movmem( ptemp, defaultd,256);                /* Make a copy for later */
  2181.     p2cstr((StringPtr) defaultd);        
  2182.     HUnlock((Handle) hostR);
  2183.     ChangedResource((Handle) hostR);
  2184.     UpdateResFile(HomeResFile((Handle) hostR));
  2185.  
  2186.  
  2187.     HLock((Handle) fileR);                        /* NCSA 2.5 */
  2188.     ftemp=*fileR;                                /* NCSA 2.5 */    
  2189.     GetDItem(dtemp,8,&dItem,&dHand,&dBox);        /* NCSA 2.5 */
  2190.     GetIText(dHand, (Str255) ftemp);            /* NCSA 2.5 */
  2191.     HUnlock((Handle) fileR);                    /* NCSA 2.5 */
  2192.     ChangedResource((Handle) fileR);            /* NCSA 2.5 */
  2193.     UpdateResFile(HomeResFile((Handle) fileR));    /* NCSA 2.5 */
  2194.  
  2195.  
  2196.     DisposDialog( dtemp);
  2197.  
  2198.     return(1);
  2199. } /* driverconf */
  2200.  
  2201.  
  2202. /*********************************************************************/
  2203. /*  parse
  2204. *   look at the string which has just come in from outside and
  2205. *   check for special sequences that we are interested in.
  2206. *
  2207. *   Tries to pass through routine strings immediately, waiting for special
  2208. *   characters ESC and 255 to change modes.
  2209. */
  2210.  
  2211. #define STNORM    0
  2212. #define EOF        236
  2213. #define    SE        240
  2214. #define    NOP        241
  2215. #define DM        242
  2216. #define BREAK    243
  2217. #define IP        244
  2218. #define AO        245
  2219. #define    AYT        246
  2220. #define    EC        247
  2221. #define EL        248
  2222. #define GA        249
  2223. #define    SB        250
  2224. #define WILLTEL 251
  2225. #define WONTTEL 252
  2226. #define DOTEL    253
  2227. #define DONTTEL 254
  2228. #define    IAC        255
  2229. #define    SEXECUTE            200
  2230. #define    NEGOTIATE            1
  2231. #define ESCFOUND             5
  2232. #define IACFOUND             6
  2233.  
  2234. #define BINARY                 0
  2235. #define ECHO                1
  2236. #define SGA                    3
  2237. #define STATUS                5
  2238. #define TIMING                6
  2239. #define    TERMTYP                24
  2240. #define GS                    29
  2241. #define NAWS                31
  2242. #define    TERMSPEED            32
  2243. #define REMOTEFLOW            33
  2244. #define LINEMODE             34
  2245.     #define MODE 1
  2246.         #define EDIT     1
  2247.         #define TRAPSIG  2
  2248.         #define MODE_ACK 4
  2249.  
  2250.  
  2251. #define FORWARDMASK 2
  2252.  
  2253. #define    substate    tw->substat
  2254.  
  2255. void parse
  2256.   (
  2257.     struct WindRec *tw,
  2258.     unsigned char *st,
  2259.     int cnt
  2260.   )
  2261. {
  2262.     int i,temptw;
  2263.     unsigned char *mark,*orig;
  2264.     char parsedat[40];
  2265.     char mesg[50];
  2266. #ifdef OPTSDEBUG
  2267.     char munger[255]; 
  2268. #endif
  2269.  
  2270.  
  2271.  
  2272.  
  2273.  
  2274.  
  2275.     orig = st;                /* remember beginning point */
  2276.     mark = st + cnt;        /* set to end of input string */
  2277.  
  2278. /*
  2279. * raw mode for debugging, passes through escape sequences and other
  2280. * special characters as <27> symbols
  2281. */
  2282.     if (tw->termstate == DUMBTYPE) {
  2283.         for (i=0; i < cnt; i++,st++)            /* put on screen raw */
  2284.             if (*st == 27 || *st > 126) {
  2285.                 sprintf(parsedat,"<%d>",*st);
  2286.                 VSwrite(tw->vs,parsedat,strlen(parsedat));    /* send to virtual screen */
  2287.             }
  2288.             else
  2289.                 VSwrite(tw->vs,st,1);
  2290.     }
  2291.     else {
  2292.  
  2293. /*
  2294. *  traverse string, looking for any special characters which indicate that
  2295. *  we need to change modes.
  2296. */
  2297.     while (st < mark) {
  2298.  
  2299.         switch (tw->telstate) {
  2300.             case GS:
  2301.             case ESCFOUND:
  2302.                 if (tw->tektype != -1) {    /* NCSA 2.5: we'll allow the TEK */
  2303.                 if ((*st == 12) || (tw->telstate == GS))    /* esc-FF */
  2304.                 {
  2305.                     if ((tw->termstate == VTEKTYPE) || (!tw->tekclear))
  2306.                     {
  2307.                         if (tw->termstate == VTEKTYPE)
  2308.                             putln("Entering Tek mode");
  2309.                         else if (tw->curgraph > -1)
  2310.                             detachGraphics(tw->curgraph);
  2311.                         if (tw->curgraph <=  -1)
  2312.                         {
  2313.                             temptw = VGnewwin(1,tw->vs);
  2314.                             if (temptw > -1)
  2315.                             {
  2316.                                 tw->curgraph = temptw;
  2317.  
  2318.                                 VGgiveinfo(temptw);
  2319.                                 RGattach(temptw,tw->vs,tw->name);
  2320.                             }
  2321.                             else
  2322.                                 tw->telstate = STNORM;
  2323.                         }
  2324.                         if (tw->telstate != STNORM)
  2325.                             tw->termstate = TEKTYPE;
  2326.                     }
  2327.                     if (tw->telstate == GS)
  2328.                     {
  2329.                         st++;
  2330.                         VGwrite(tw->curgraph,"\035",1);
  2331.                     }
  2332.                     else if (tw->telstate != STNORM)
  2333.                         VGwrite(tw->curgraph,"\037\033\014",3);
  2334.                     tw->telstate = STNORM;
  2335.                     break;
  2336.                 }
  2337.                 }        /* NCSA 2.5 */
  2338.             
  2339.                 if (*st == '^')                /* ESC- ^ */
  2340.                 {
  2341.                     tw->termstate = RASTYPE;
  2342.                     tw->telstate = STNORM;
  2343.                     VRwrite("\033^",2);        /* Put it through */
  2344.                     orig = ++st;
  2345.                     break;
  2346.                 }
  2347.                 
  2348.                 if (tw->termstate == TEKTYPE)
  2349.                     VGwrite(tw->curgraph,"\033",1);
  2350.                 else if (tw->termstate  == RASTYPE)
  2351.                     VRwrite("\033",1);
  2352.                 else
  2353.                     VSwrite(tw->vs,"\033",1);    /* send the missing ESC */
  2354.                 tw->telstate = STNORM;
  2355.                 break;
  2356.             case IACFOUND:         /* telnet option negotiation */
  2357.                 if (*st == 255) {        /* real data = 255 */
  2358.                     st++;                /* real 255 will get sent */
  2359.                     tw->telstate = STNORM;
  2360.                     break;
  2361.                 }
  2362.                 if ( 239 < *st ) {
  2363.                     tw->telstate = *st;        /* by what the option is */
  2364.                     st++;
  2365.                     break;
  2366.                 }
  2367.                 putln("Strange telnet option!");
  2368.                 tw->telstate = STNORM;
  2369.                 orig=st;
  2370.                 break;
  2371.  
  2372.             case EOF:
  2373. #ifdef OPTSDEBUG
  2374.                 sprintf(munger,"RECV: %s",telstates[tw->telstate - SE]);
  2375.                 putln(munger); 
  2376. #endif
  2377.                 orig=st;
  2378.                 tw->telstate=STNORM;
  2379.                 
  2380.                 break;
  2381.  
  2382.             case EL:                /* thanx Quincey!!! */
  2383.             case EC:
  2384.             case AYT:
  2385.             case AO:
  2386.             case IP:
  2387.             case BREAK:
  2388.             case DM:
  2389.             case NOP:
  2390.             case SE:
  2391. #ifdef OPTSDEBUG
  2392.                 sprintf(munger,"RECV: %s",telstates[tw->telstate - SE]);
  2393.                 putln(munger); 
  2394. #endif
  2395.                 tw->telstate = STNORM;
  2396.                 orig=st;
  2397.  
  2398.             case GA:
  2399.                 orig=st;
  2400.                 tw->telstate = STNORM;
  2401.                 break;
  2402.             case DOTEL:
  2403. #ifdef OPTSDEBUG
  2404.                 sprintf(munger,"RECV: %s %s",telstates[tw->telstate-SE],teloptions[*st]);
  2405.                 putln(munger); 
  2406. #endif
  2407.  
  2408.                 switch( *st) {
  2409.                     case  SGA:        /* Sure we'll supress GA */
  2410.                         if (!tw->Isga)
  2411.                             {
  2412.                             tw->Isga=1;
  2413.                             sprintf(parsedat,"%c%c%c",255,WILLTEL,*st);
  2414.                             netpush(tw->port);
  2415.                             netwrite(tw->port,parsedat,3);
  2416.                             }
  2417.                         tw->telstate = STNORM;
  2418.                         orig = ++st;
  2419.                         break;
  2420.                     case TERMTYP:        /* And we'll even tell you about ourselves */
  2421.                         if (!tw->Ittype)
  2422.                             {
  2423.                             tw->Ittype=1;
  2424.                             sprintf(parsedat,"%c%c%c",255,WILLTEL,*st);
  2425.                             netpush(tw->port);
  2426.                             netwrite(tw->port,parsedat,3);
  2427.                             }
  2428.                         tw->telstate = STNORM;
  2429.                         orig = ++st;
  2430.                         break;
  2431.  
  2432.                     case  NAWS:            /* NCSA: sure, I like changing the window size! */
  2433.                         tw->naws =1;                                    /* NCSA: this session is now NAWS */
  2434.                         sprintf(parsedat,"%c%c%c",255,WILLTEL,*st);        /* NCSA: reply, we will to NAWS */
  2435.                         netpush(tw->port);                                /* NCSA */
  2436.                         netwrite(tw->port,parsedat,3);                    /* NCSA: send it out */
  2437. #if 1
  2438.                         sprintf(parsedat,"%c%c%c%c%c%c%c%c%c",IAC,SB,    /* BYU 2.4.16 */
  2439.                             NAWS,(char)0,(unsigned char)tw->width,        /* BYU 2.4.16 */
  2440.                             (char)0,(unsigned char)tw->rows,IAC,SE);    /* BYU 2.4.16 */
  2441.                         netpush(tw->port);                                /* BYU 2.4.16 */
  2442.                         netwrite(tw->port,parsedat,9);                    /* BYU 2.4.16 */
  2443. #endif
  2444.                         tw->telstate = STNORM;                            /* NCSA */
  2445.                         orig = ++st;                                    /* NCSA */
  2446.                         break;                                            /* NCSA */
  2447.  
  2448.                     case LINEMODE:  /* Sure I'll do line mode... */
  2449.                         if (tw->lineAllow) 
  2450.                             {
  2451.                             sprintf(parsedat,"%c%c%c",IAC,WILLTEL,*st++);
  2452.                             putln("*** using linemode");
  2453.                             
  2454.                             netwrite(tw->port,parsedat,3);
  2455.                             
  2456.                             sprintf(parsedat,"%c%c%c%c",IAC,SB,LINEMODE,SLC);
  2457.                             netwrite(tw->port,parsedat,4);
  2458.                             putln("SENT: IAC SB LINEMODE SLC");
  2459.     
  2460.                             for (i=1; i<19; i++){
  2461.                                 if (tw->slc[i]==-1)
  2462.                                     {
  2463.                                     sprintf(parsedat,"%c%c%c",i,SLC_NOSUPPORT,0);
  2464. #ifdef OPTSDEBUG
  2465.                                     sprintf(munger,"     %s NO_SUPPORT 0",LMoptions[i]);
  2466. #endif
  2467.                                     }
  2468.                                 else
  2469.                                     {
  2470.                                     sprintf(parsedat,"%c%c%c",i,SLC_CANTCHANGE,(char)tw->slc[i]);
  2471. #ifdef OPTSDEBUG
  2472.                                     sprintf(munger,"     %s CANTCHANGE %i",LMoptions[i],(int)tw->slc[i]);
  2473. #endif
  2474.                                     }
  2475. #ifdef OPTSDEBUG
  2476.                                 putln(munger);
  2477. #endif
  2478.                                 netwrite(tw->port,parsedat,3);
  2479.                                 }
  2480.     
  2481.                             putln("SENT: IAC SE");
  2482.                             sprintf(parsedat,"%c%c",IAC,SE);
  2483.                             netwrite(tw->port,parsedat,2);
  2484.                             }
  2485.                             
  2486.                         else 
  2487.                             {
  2488.                             sprintf(parsedat,"%c%c%c",IAC,WONTTEL,LINEMODE);
  2489.                             netwrite(tw->port,parsedat,3);
  2490.  
  2491.                             putln("*** linemode not allowed");
  2492.                             }
  2493.  
  2494.                         break;
  2495.                     default:                /* But, we won't do .... */
  2496.                         sprintf(parsedat,"%c%c%c",255,WONTTEL,*st++);
  2497.                         putln("didnt do option");
  2498.                         netwrite(tw->port,parsedat,3);  
  2499.                         break;
  2500.                     }
  2501.                 tw->telstate = STNORM;
  2502.                 orig = st;
  2503.                 break;
  2504.  
  2505.             case DONTTEL:
  2506. #ifdef NOTNEEDED
  2507.                 switch( *st) {
  2508.                     case  3:        /* Sure we'll supress GA */
  2509.                         if (!tw->Isga)
  2510.                             break;
  2511.                         tw->Isga=0;
  2512.                         sprintf(parsedat,"%c%c%c",255,WONTTEL,*st++);
  2513.                         netpush(tw->port);
  2514.                         netwrite(tw->port,parsedat,3);
  2515.                         break;
  2516.                     case 24:        /* And we'll even tell you about ourselves */
  2517.                         if (!tw->Ittype)
  2518.                             break;
  2519.                         tw->Ittype=0;
  2520.                         sprintf(parsedat,"%c%c%c",255,WONTTEL,*st++);
  2521.                         netpush(tw->port);
  2522.                         netwrite(tw->port,parsedat,3);
  2523.                         break;
  2524.                     
  2525.                     default: 
  2526.                         st++;     /* this data is garbage */
  2527.                         break;
  2528.                     }
  2529. #endif
  2530.  
  2531. #ifdef OPTSDEBUG
  2532.                     sprintf(munger,"RECV: %s %s",telstates[tw->telstate-SE],teloptions[*st]);
  2533.                     putln(munger); 
  2534. #endif
  2535.                     tw->telstate = STNORM;
  2536.                     orig = ++st;
  2537.                 break;
  2538.  
  2539.             case WILLTEL:
  2540. #ifdef OPTSDEBUG
  2541.                 sprintf(munger,"SENT: %s %s",telstates[tw->telstate-SE],teloptions[*st]);
  2542.                 putln(munger); 
  2543. #endif
  2544.  
  2545.                 tw->telstate = STNORM;
  2546.                 switch(*st++) {
  2547.                     case 1:             /* Echo on the other end*/
  2548.                         if (!tw->echo)
  2549.                             break;
  2550.                         tw->echo = 0;    /* Ok, in that case they can echo... */
  2551.                         changeport(scrn,scrn);
  2552.                         sprintf(parsedat,"%c%c%c",255,DOTEL,1);
  2553.                         netpush(tw->port);
  2554.                         netwrite(tw->port,parsedat,3);  /* refuse it */
  2555.                         break;
  2556.                     case 3:                /* Supress GA */
  2557.                         if (tw->Usga)
  2558.                             break;
  2559.                         tw->Usga = 1;    /* Go Ahead and supress GA */
  2560.                         sprintf(parsedat,"%c%c%c",255,DOTEL,3);
  2561.                         netpush(tw->port);
  2562.                         netwrite(tw->port,parsedat,3);  /* refuse it */
  2563.                         break;
  2564.                     case TIMING:                /* Timing Mark */
  2565.                         tw->timing = 0;
  2566.                         break;
  2567.                     default:
  2568.                         sprintf(parsedat,"%c%c%c",255,DONTTEL,*(st-1));
  2569.                         netwrite(tw->port,parsedat,3);  /* refuse it */
  2570.                 }
  2571.                 orig = st;
  2572.                 break;
  2573.  
  2574.             case WONTTEL:
  2575. #ifdef OPTSDEBUG
  2576.                 sprintf(munger,"SENT: %s %s",telstates[tw->telstate-SE],teloptions[*st]);
  2577.                 putln(munger); 
  2578. #endif
  2579.                 tw->telstate = STNORM;
  2580.                 switch(*st++) {         /* which option? */
  2581.                     case ECHO:             /* echo */
  2582.                         if (tw->echo)
  2583.                             break;
  2584.                         tw->echo = 1;    /* Ok, I will echo if I have to... */
  2585.                         changeport(scrn,scrn);
  2586.                         sprintf(parsedat,"%c%c%c",IAC,DONTTEL,ECHO);
  2587.                         netpush(tw->port);
  2588.                         netwrite(tw->port,parsedat,3);  /* refuse it */
  2589.                         break;
  2590.                     case 3:
  2591.                         if (!tw->Usga)
  2592.                             break;
  2593.                         tw->Usga = 0;
  2594.                         sprintf(parsedat,"%c%c%c",255,DONTTEL,*(st-1));
  2595.                         netpush(tw->port);
  2596.                         netwrite(tw->port,parsedat,3);  /* refuse it */
  2597.                         break;
  2598.                     case TIMING:                /* Timing Mark */
  2599.                         tw->timing = 0;
  2600.                         break;
  2601.                     default:
  2602.                         break;
  2603.                 }
  2604.                 orig = st;
  2605.                 break;
  2606.  
  2607.             case SB:
  2608.                 tw->telstate = NEGOTIATE;
  2609.                 orig=st;
  2610.                 i = substate=0;                /* Defined for each */
  2611.                 break;
  2612.  
  2613.             case NEGOTIATE:
  2614.                 if (substate <200) {
  2615.                     switch( *st) {
  2616.                         case IAC:
  2617.                             if (*(st+1) ==IAC) 
  2618.                                 {
  2619.                                 parsedat[i++]=*st++;
  2620.                                 parsedat[i++]=*st++;
  2621.                                 }
  2622.                             else 
  2623.                                 {
  2624.                                 parsedat[i]='\0';
  2625.                                 substate=*st++;
  2626.                                 }                            
  2627.                             break;
  2628.                         default:
  2629.                             parsedat[i++]=*st++;
  2630.                             break;
  2631.                         }
  2632.                     } else {
  2633.                     switch( substate) {
  2634.                         case IAC:
  2635.                             substate=*st++;
  2636.                             if (substate==SE) {
  2637.                                 switch( parsedat[0]) {
  2638.                                 case TERMTYP:
  2639.                                     if (parsedat[1]==1) {
  2640.                                         char s[50];
  2641.  
  2642.  
  2643. #ifdef OPTSDEBUG
  2644.                                         sprintf(munger,"RECV: SB TERMINAL-TYPE SEND\r\nSEND: SB TERMINAL-TYPE IS %s\r\n",TermType);
  2645.                                         putln(munger); 
  2646. #endif
  2647.                                         netpush(tw->port);
  2648.                                         netwrite(tw->port,"\377\372\030\000",4);
  2649.                                         netpush(tw->port);
  2650.                                         sprintf(s,"%s\377\360",TermType);
  2651.                                         netwrite(tw->port, s, strlen(s));
  2652.                                         }
  2653.                                     break;
  2654. /* this is the new line-mode stuff */
  2655.  
  2656.                                 
  2657.                                         case LINEMODE:
  2658.                                             switch(parsedat[1]){
  2659.                                                 char s[50];
  2660.  
  2661.                                                 case MODE:
  2662.  
  2663.                                                     if ((parsedat[2] & EDIT) &&tw->lineAllow)
  2664.                                                         tw->lmflag=1;
  2665.                                                     /*else
  2666.                                                         tw->lmflag=0; */
  2667.                                                         
  2668.                                             
  2669.                                                     sprintf(mesg,"value of tw->lmflag: %i",(int)tw->lmflag);
  2670.                                                     putln(mesg);
  2671.                                                     putln("SENT: IAC SB LINEMODE MODE");
  2672.  
  2673.                                                     sprintf(s,"%c%c%c%c",IAC,SB,LINEMODE,MODE);
  2674.                                                     netwrite(tw->port,s,4);
  2675.                                                     sprintf(s,"%c%c%c",parsedat[2]|MODE_ACK,IAC,SE);
  2676.                                                     netwrite(tw->port,s,3); 
  2677. #ifdef OPTSDEBUG
  2678.                                                     sprintf(munger,"     %i IAC SE",(int)(parsedat[2]|MODE_ACK));
  2679.                                                     putln(munger); 
  2680. #endif
  2681.                                                     break;
  2682.                                                 case DOTEL:
  2683.                                                     netwrite(tw->port,"\377\372\042",3);
  2684.                                                     sprintf(s,"%c\002\377\360",WONTTEL);
  2685.                                                     netwrite(tw->port,s,strlen(s));
  2686.                                                     break;
  2687.  
  2688.                                                 case WILLTEL:
  2689.                                                     netwrite(tw->port,"\377\372\042",3);
  2690.                                                     sprintf(s,"%c\002\377\360",DONTTEL);
  2691.                                                     netwrite(tw->port,s,strlen(s));
  2692.                                                     break;
  2693.  
  2694.  
  2695.                                                 case SLC:
  2696. #ifdef OPTSDEBUG
  2697.                                                     sprintf(munger,"RECV: SB LINEMODE SLC");
  2698.                                                     putln(munger);
  2699. #endif
  2700.                                                     for(i=2;(parsedat[i]!='\0') && (parsedat[i]!=IAC); i+=3) 
  2701.                                                         {
  2702. #ifdef OPTSDEBUG
  2703.                                                         if(parsedat[i+1] & SLC_AWK)
  2704.                                                             sprintf(munger,"     %s %s|AWK %d",LMoptions[parsedat[i]],LMflags[parsedat[i+1] & SLC_LEVELBITS],parsedat[i+2]);
  2705.                                                         else
  2706.                                                             sprintf(munger,"     %s %s %d",LMoptions[parsedat[i]],LMflags[parsedat[i+1] & SLC_LEVELBITS],parsedat[i+2]);
  2707.                                                         putln(munger);
  2708. #endif
  2709.                                                         if ((unsigned char)(parsedat[i+2])==IAC) i++;
  2710.  
  2711.                                                         }    /* end for */
  2712.                     
  2713.                                                     /* First check to see if we need to reply */
  2714.                                                     for (i=2;(parsedat[i]!='\0') && (parsedat[i]!=IAC); i+=3)
  2715.                                                         {
  2716.                                                         if (!(parsedat[i+1] & SLC_AWK)) break;
  2717.                                                         if ((unsigned char)(parsedat[i+2])==IAC) i++;
  2718.                                                         }
  2719.     
  2720.                                                     /* if we do then send a reply */
  2721.                                                     if ((parsedat[i]!=IAC) && (parsedat[i]!='\0'))
  2722.                                                         {
  2723.                                                         sprintf(s,"%c%c%c%c",IAC,SB,LINEMODE,SLC);
  2724.                                                         netwrite(tw->port,s,4);
  2725.                                                         putln("SENT: IAC SB LINEMODE SLC");
  2726.         
  2727.  
  2728. #ifdef NEWSLC
  2729.                                                         for (i=2; (parsedat[i]!='\0') && (parsedat[i]!=IAC); i+=3)
  2730.                                                             {
  2731.                                                             if (!(parsedat[i+1] & SLC_AWK))        /* no response of ACK set */
  2732.                                                                 {
  2733.                                                                 if (parsedat[i+1] != SLC_NOSUPPORT)
  2734.                                                                     {
  2735.                                                                     sprintf(s,"%c%c%c",parsedat[i],SLC_NOSUPPORT,0);
  2736. #ifdef OPTSDEBUG
  2737.                                                                     sprintf(munger,"     %s NOSUPPORT 0",LMoptions[parsedat[i]]);
  2738. #endif
  2739.                                                                     }
  2740.                                                                 else        /* Acknowledge the No_Support case */
  2741.                                                                     {
  2742.                                                                     sprintf(s,"%c%c%c",parsedat[i],SLC_AWK|SLC_NOSUPPORT,(char)0);
  2743. #ifdef OPTSDEBUG
  2744.                                                                     sprintf(munger,"     %s NOSUPPORT|AWK 0",LMoptions[parsedat[i]]);
  2745. #endif
  2746.                                                                     }                                                                
  2747. #ifdef OPTSDEBUG
  2748.                                                                 putln(munger);
  2749. #endif
  2750.                                                                 netwrite(tw->port,s,3);
  2751.                                                                 }
  2752.                                                                 if ((unsigned char)(parsedat[i+2])==IAC) i++;
  2753.                                                             }
  2754.  
  2755. #else
  2756.                                                         for (i=2; (parsedat[i]!='\0') && (parsedat[i]!=IAC); i+=3)
  2757.                                                             {
  2758.                                                             if (!(parsedat[i+1] & SLC_AWK))
  2759.                                                                 {
  2760.                                                                 if (tw->slc[parsedat[i]]==-1)
  2761.                                                                     {
  2762.                                                                     sprintf(s,"%c%c%c",i,SLC_NOSUPPORT,0);
  2763. #ifdef OPTSDEBUG
  2764.                                                                     sprintf(munger,"     %s %s 0",LMoptions[i],LMflags[parsedat[i+1] & SLC_LEVELBITS]);
  2765. #endif
  2766.                                                                     }
  2767.                                                                 else
  2768.                                                                     {
  2769.                                                                     sprintf(s,"%c%c%c",i,SLC_CANTCHANGE,(char)tw->slc[parsedat[i]]);
  2770. #ifdef OPTSDEBUG
  2771.                                                                     sprintf(munger,"     %s %s 0",LMoptions[i],LMflags[parsedat[i+1] & SLC_LEVELBITS]);
  2772. #endif
  2773.                                                                     }                                                                
  2774. #ifdef OPTSDEBUG
  2775.                                                                 putln(munger);
  2776. #endif
  2777.                                                                 netwrite(tw->port,s,3);
  2778.                                                                 if (parsedat[i+2]==IAC) i++;
  2779.                                                                 }
  2780.                                                             }
  2781.                                                             
  2782. #endif
  2783.                                                         sprintf(s,"%c%c",IAC,SE);
  2784.                                                         netwrite(tw->port,s,2);
  2785.                                                         }
  2786.  
  2787.                                                 /* otherwise just exit */
  2788.                                                     break;
  2789.  
  2790.                                                 default:
  2791.                                                     break;
  2792.  
  2793.                                                 }
  2794.                                         break;
  2795.  
  2796. /* end of all the new line-mode shit */                                
  2797.                                 
  2798.                                 
  2799.                                 default:
  2800.                                     break;
  2801.                                 }
  2802.                             }
  2803.                             orig=st;
  2804.                             tw->telstate=STNORM;
  2805.                             break;
  2806.                         default:
  2807.                             orig=st;
  2808.                             tw->telstate=STNORM;
  2809.                             break;
  2810.                         }
  2811.                     }
  2812.  
  2813.                 break;
  2814.             default:
  2815.                 tw->telstate = STNORM;
  2816.                 break;
  2817.         }
  2818.  
  2819. /*
  2820. * quick scan of the remaining string, skip chars while they are
  2821. * uninteresting
  2822. */
  2823.         if (tw->telstate == STNORM) {
  2824. /*
  2825. *  skip along as fast as possible until an interesting character is found
  2826. */
  2827.             if (!tw->eightbit) {                                            /* BYU 2.4.10 */
  2828.                 while (st < mark) {                                            /* BYU 2.4.10 */
  2829.                     if (*st == IAC)                                         /* BYU 2.4.10 */
  2830.                         break;                                                /* BYU 2.4.10 */
  2831.                     else {                                                    /* BYU 2.4.10 */
  2832.                         *st &= 0x7f;                                         /* BYU 2.4.10 */
  2833.                         if (*st == ESC  || *st == GS)                         /* BYU 2.4.10 */
  2834.                             break;                                            /* BYU 2.4.10 */
  2835.                         st++;                                                /* BYU 2.4.10 */
  2836.                 }    }                                                        /* BYU 2.4.10 */
  2837.             } else                                                             /* BYU 2.4.10 */
  2838.                 while (st < mark && *st != ESC  && *st < 128 && *st != GS)     /* BYU 2.4.10 */
  2839.                     st++;                                                     /* BYU 2.4.10 */
  2840. /*
  2841. *  send the string where it belongs
  2842. */
  2843.             if (!tw->timing) {
  2844.                 if (tw->termstate == TEKTYPE) {
  2845.                     int i;
  2846.                     
  2847.                     i = VGwrite( tw->curgraph,orig,  st-orig);
  2848.                     if (i < (st - orig)) {
  2849.                         detachGraphics(tw->curgraph);
  2850.                         st = orig + i;
  2851.                         putln("From Tek to VS");
  2852.                         }
  2853.                     }
  2854.                 else if (tw->termstate == RASTYPE) {
  2855.                     int i;
  2856.                     
  2857.                     i= VRwrite( orig, st-orig);
  2858.                     if (i <(st-orig)) {
  2859.                         tw->termstate = VTEKTYPE;
  2860.                         st = orig +i;                /* Next char to parse */
  2861.                         putln("From VR to VS");
  2862.                         }
  2863.                     }
  2864.                 else 
  2865.                     VSwrite( tw->vs,orig,st-orig);    /* send to virtual VT102 */
  2866.                 }
  2867.  
  2868.             orig = st;                /* forget what we have sent already */
  2869.  
  2870.             if (st < mark)
  2871.             switch (*st) {
  2872.                 case 255:            /* telnet IAC */
  2873.                     tw->telstate = IACFOUND;
  2874.                     st++;
  2875.                     break;
  2876.                 case GS:
  2877.                     if (tw->telstate != GS)
  2878.                     {
  2879. #if 0    /* BYU */
  2880.                         putln("Hey, were here @ GS!!!");
  2881. #endif
  2882.                         tw->telstate = GS;
  2883.                     }
  2884.                     else
  2885.                         tw->telstate = STNORM;
  2886.                     st++;
  2887.                     break;
  2888.                     
  2889.                 case ESC:            /* ESCape code */
  2890.                     if (st == mark-1 || *(st+1) == 12 || *(st+1) == '^' ) {
  2891.                         tw->telstate = ESCFOUND;
  2892.                     }
  2893.                     st++;            /* strip or accept ESC char */
  2894.  
  2895.                     break;
  2896. #ifdef WORKSOLD
  2897.                 default:
  2898.                     if (*st > 127) {
  2899.                         putln("Strange char > 128!");
  2900.                         (*st++)&=0x7f;    /* NVT Ascii says I can... */
  2901.                       if (st==mark)     /*new addition */
  2902.                           VSwrite(tw->vs,orig,1);
  2903. #endif
  2904.                 default:
  2905.                     if (*st++ > 127) {
  2906. /*                        putln("Strange char > 128!");        /* BYU 2.4.10 */
  2907.                     /*    (*st++)&=0x7f;*/    /* NVT Ascii says I can... */
  2908.                       if (st==mark)     /*new addition */
  2909.                           VSwrite(tw->vs,orig,1);
  2910.  
  2911.  
  2912.                     }
  2913.                     break;
  2914.             }
  2915.  
  2916.         }
  2917.  
  2918.     }  /* end while */
  2919.     }
  2920. } /* parse */
  2921.  
  2922. int VGalive
  2923.   (
  2924.     int dnum
  2925.   )
  2926. {
  2927.     int i;
  2928.  
  2929.     i=0;
  2930.     while((i<numwindows) && (dnum!=screens[i].curgraph)) i++;
  2931.     if (i<numwindows) {
  2932.         return(1);
  2933.         }
  2934.     else {
  2935.         i=0;
  2936.         while ((i<graphs) && (dnum!=oldgraph[i])) i++;
  2937.         if (i<graphs)
  2938.             return(1);
  2939.         }
  2940.     return(0);
  2941. }
  2942.  
  2943. void destroyGraphics
  2944.   (
  2945.     int dnum
  2946.   )
  2947. {
  2948.     int i;
  2949.  
  2950.     i=0;
  2951.     while((i<numwindows) && (dnum!=screens[i].curgraph)) i++;
  2952.     if (i<numwindows) {
  2953.         screens[i].curgraph=-1;
  2954.         screens[i].termstate=VTEKTYPE;
  2955.         screens[i].enabled=1;
  2956.         }
  2957.     else {
  2958.         i=0;
  2959.         while ((i<graphs) && (dnum!=oldgraph[i])) i++;
  2960.         while (i<(MaxGraph-1))
  2961.             oldgraph[i]=oldgraph[++i];            /* Bump everyone down one slot */
  2962.         graphs--;                                /* One less graph to feed */
  2963.         }
  2964.     VGclose( dnum);
  2965. }
  2966.  
  2967. int isHFS
  2968.   (
  2969.     void
  2970.   )
  2971. {
  2972.     return
  2973.         HFS;
  2974. }
  2975.  
  2976. FindByVG(vg)
  2977. int vg;
  2978. {
  2979.     int i=0;
  2980.  
  2981.     while((i<numwindows) && (vg!=screens[i].curgraph)) i++;
  2982.     if (i>=numwindows) return(-1);
  2983.     return(i);
  2984. }
  2985.  
  2986. void TekEnable
  2987.   (
  2988.     int vg
  2989.   )
  2990. {
  2991.     int change;
  2992.  
  2993.     change=FindByVG( vg);
  2994.     if (change>=0)
  2995.         screens[change].enabled=1;
  2996. }
  2997.  
  2998. void TekDisable
  2999.   (
  3000.     int vg
  3001.   )
  3002. {
  3003.     int change;
  3004.  
  3005.     change=FindByVG( vg);
  3006.     if (change>=0)
  3007.         screens[change].enabled=0;
  3008. }
  3009.  
  3010. pascal void OutlineItem( dlog, itm)
  3011. DialogPtr dlog;
  3012. short itm;
  3013. {
  3014.     Rect ibox;
  3015.     char **ihndl;
  3016.     short typ;
  3017.     int item=itm;
  3018.     
  3019.     GetDItem( dlog, item, &typ, &ihndl, &ibox);
  3020.     PenSize( 3,3);
  3021.     InsetRect( &ibox, -4,-4);
  3022.     FrameRoundRect( &ibox, 16,16);
  3023. }
  3024.  
  3025. pascal void VersionNumber( dlog, itm)
  3026. DialogPtr dlog;
  3027. short itm;
  3028. {
  3029.     Rect ibox;
  3030.     char **ihndl;
  3031.     short typ;
  3032.     int item=itm;
  3033.  
  3034.     GetDItem( dlog, item, &typ, &ihndl, &ibox);
  3035.     TextFont( 3);
  3036.     TextSize( 9);
  3037.     MoveTo( ibox.left+((ibox.right-ibox.left)/2)-(stringwidth( VERSION)/2), ibox.bottom-2);
  3038.     drawstring( VERSION );
  3039. }
  3040.  
  3041.  
  3042. char *rindex(s,c)
  3043.     char *s,c;
  3044.     {
  3045.     char *p;
  3046.     
  3047.     p = NULL;
  3048.     
  3049.     while (*s) {
  3050.         if (*s == c)
  3051.             p = s;
  3052.         s++;
  3053.         }
  3054.  
  3055.     return(p);
  3056.  
  3057. }
  3058.  
  3059.  
  3060.  
  3061. void DoTheMenuChecks()
  3062. {
  3063.     short    active;
  3064.     short    windownum;
  3065.     
  3066.     if (numwindows>0)
  3067.         {
  3068.         EnableItem( myMenus[Conn],0);
  3069.         DrawMenuBar();
  3070.         }
  3071.  
  3072.     else 
  3073.         {
  3074.         DisableItem(myMenus[Conn],0);
  3075.         DrawMenuBar();
  3076.         }
  3077.         
  3078.     active =0;
  3079.     
  3080.     for (windownum=0;windownum<numwindows;windownum++)
  3081.         if (!screens[windownum].active) active++;
  3082.         
  3083.     if (active<2)    
  3084.         DisableItem(myMenus[Conn],COnext);
  3085.     else EnableItem(myMenus[Conn],COnext);
  3086.  
  3087.     if (!active)
  3088.         {
  3089. /*        DisableItem(myMenus[Edit],EDcopy);
  3090.         DisableItem(myMenus[Edit],EDcopyt); */
  3091.         DisableItem(myMenus[Edit],EDpaste);
  3092.         DisableItem(myMenus[Emul],0);
  3093.         DrawMenuBar();
  3094.         }
  3095.     else 
  3096.         {
  3097. /*        EnableItem(myMenus[Edit],EDcopy);
  3098.         EnableItem(myMenus[Edit],EDcopyt); */
  3099.         EnableItem(myMenus[Edit],EDpaste);
  3100.         EnableItem( myMenus[Emul],0);
  3101.         DrawMenuBar();
  3102.         }
  3103.                 
  3104. }